-
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
strictNullChecks limits what types can be accessed with indexed access types #21975
Comments
I'm don't think this is a duplicate @mhegazy. This involves mapped types instead of the typeof operator. |
This issue may generalize more correctly to a feature request that the compiler should chose the "more useful" type when mapping through union types. For example the following example applies without
|
See #14366 for the closer dupe. |
Would it be better to handle #14366 in the more general case by handling all union types? Should I update this issue? |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.7.1-insiders.20180127
Search Terms: strictNullChecks mapped types property undefined generated types
Code
Expected behavior: Type
ShouldBeString
is a string type. This is useful especially for generated types where it isn't possible to write{ baz: string }
as a separate type.Actual behavior: Accessing
'baz'
errors withProperty 'baz' does not exist on type '{ baz: string; } | undefined'.
Playground Link:
Make sure to toggle
strictNullChecks
on: https://www.typescriptlang.org/play/#src=interface%20Foo%20%7B%0D%0A%20%20%20%20bar%3F%3A%20%7B%0D%0A%20%20%20%20%20%20%20%20baz%3A%20string%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Atype%20ShouldBeString%20%3D%20Foo%5B'bar'%5D%5B'baz'%5DRelated Issues: #16108 #6606
The text was updated successfully, but these errors were encountered: