-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapped type optional -> required property issue #13224
Comments
As a side note, it would be awesome if you could iterate at runtime on the keys of an interface. I guess that starts moving into the reflection questions, but it would be super handy if code could be emitted based on type information. So not runtime reflection but static templating. I probably need to generate the styleguide from the typescript source rather than the approach I am taking. |
Mapped types that are a homomorphic transformation are treated specially in the type system. the above type You however change the mapping to make it a non-homomorphic transformation as such: type PropDescriptions<T, K extends string> = {
[P in K]: string
} and you would instantiate it with: const expected: PropDescriptions<ThingProps, keyof ThingProps> = ... Notice the constraint on It is worth noting that if the constraint was |
Thanks, have opened a PR in the docs which adds some of this information. Appreciate the good explanation. |
It would also be good to extend the docs to explain how to use the |
TypeScript Version: 2.1.4
Code
https://github.com/JakeGinnivan/TypeScriptMappedTypeIssue
Expected behavior:
The mapped type
Is marking all the properties as required, I would expect this to fail:
with
Property 'prop2' is missing in type {...}
Actual behavior:
No compilation error
The text was updated successfully, but these errors were encountered: