You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
strictNullChecks limits what types can be accessed with indexed access types #21975
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 with Property 'baz' does not exist on type '{ baz: string; } | undefined'.
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 strictNullChecks:
interface Foo {
bar: {
baz: string;
} | {
qux: number;
}
}
type ShouldBeString = Foo['bar']['baz']
changed the title [-]strictNullChecks limits what types can be accessed with mapped types[/-][+]strictNullChecks limits what types can be accessed with indexed access typres[/+]on Feb 20, 2018
changed the title [-]strictNullChecks limits what types can be accessed with indexed access typres[/-][+]strictNullChecks limits what types can be accessed with indexed access types[/+]on Feb 20, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
mhegazy commentedon Feb 15, 2018
Duplicate of #16108, and #17370
nomcopter commentedon Feb 15, 2018
I'm don't think this is a duplicate Mohamed Hegazy (@mhegazy). This involves mapped types instead of the typeof operator.
nomcopter commentedon Feb 20, 2018
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
strictNullChecks:https://www.typescriptlang.org/play/index.html#src=interface%20Foo%20%7B%0D%0A%20%20%20%20bar%3A%20%7B%0D%0A%20%20%20%20%20%20%20%20baz%3A%20string%3B%0D%0A%20%20%20%20%7D%20%7C%20%7B%0D%0A%20%20%20%20%20%20%20%20qux%3A%20number%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Atype%20ShouldBeString%20%3D%20Foo%5B'bar'%5D%5B'baz'%5D
[-]strictNullChecks limits what types can be accessed with mapped types[/-][+]strictNullChecks limits what types can be accessed with indexed access typres[/+][-]strictNullChecks limits what types can be accessed with indexed access typres[/-][+]strictNullChecks limits what types can be accessed with indexed access types[/+]DanielRosenwasser commentedon Feb 20, 2018
See #14366 for the closer dupe.
nomcopter commentedon Feb 20, 2018
Would it be better to handle #14366 in the more general case by handling all union types? Should I update this issue?
typescript-bot commentedon Mar 7, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.