Closed
Description
TypeScript Version: 2.7.1-insiders.20180127
Search Terms: strictNullChecks mapped types property undefined generated types
Code
interface Foo {
bar?: {
baz: string;
}
}
type ShouldBeString = Foo['bar']['baz'];
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'.
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'%5D