8000 Typescript incorrectly infer the types for Readonly optional properties. · Issue #18902 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Typescript incorrectly infer the types for Readonly optional properties. #18902
Closed
@dryganets

Description

@dryganets

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

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0