Closed
Description
TypeScript Version: 2.5.3) / 2.6.0-dev.20170930
Code
https://github.com/dryganets/typescript-bug/blob/master/index.ts
I expect this code to compile.
This example is
Expected behavior:
type guard
if (this.props.a) {
}
reduces the type from string|undefined to string.
Actual behavior:
type is still string|undefined after check.
The bug doesn't repro if I use the slightly different syntax:
export class Test extends ComponentBase<Props, {}> {
But we have some places in the app where the former syntax is required.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Typescript incorrectly infer the types for Readonly members.[/-][+]Typescript incorrectly infer the types for Readonly optional properties.[/+]mhegazy commentedon Oct 3, 2017
This is a duplicate of #15376.
this.prop.a
is a generic type,P["a"]
, and there is no way currently to narrow a generic type.It is worth noting that the compiler does the right thing on property access/ index access/ call thanks to #15576. but the type of the symbol does not change.
mhegazy commentedon Oct 17, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.