Closed
Description
Sorry if this is a dupe - I tried searching but github's search isn't great.
TypeScript Version: 2.3.1
Code
interface Nested {
child: {
prop: string
}
}
declare function maybeGetNestedValue(): Nested | null
const nested = maybeGetNestedValue()
const child: typeof nested.child = {
prop: 'value'
}
TypeScript Playground link
Note: You need to manually enable strictNullChecks under the options for this link. If I enable it and try to share it says the text buffer is too big to share.
Expected behavior: I would expect to be able to use typeof
to capture the type of this nested field, since as you can see in the emitted code in the TypeScript Playground link, there is no dereference of the nested
field emitted, so the code should always be safe.
Actual behavior: The strictNullChecks flag raises an error because the nested
field may be null
.