Skip to content
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

Typescript incorrectly infer the types for Readonly optional properties. #18902

Closed
dryganets opened this issue Oct 3, 2017 · 2 comments
Closed
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@dryganets
Copy link

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.

@dryganets dryganets changed the title Typescript incorrectly infer the types for Readonly members. Typescript incorrectly infer the types for Readonly optional properties. Oct 3, 2017
@mhegazy
Copy link
Contributor

mhegazy commented 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 mhegazy added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Oct 3, 2017
@mhegazy
Copy link
Contributor

mhegazy commented 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.

@mhegazy mhegazy closed this as completed Oct 17, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

2 participants