Skip to content

CFA issue #12457

@normalser

Description

@normalser

It's probably duplicate but it's not easy to find so apologies if it is

interface A {
    a: string // or `a: 'a'`
}

interface B {
    a: number
}

declare var c:A|B

if (typeof c.a == 'string') { // or `if (c.a == 'a')`
    c // <- Type: A|B, should be A ?
}
else {
    c // <- Type: A|B, should be B ?
}

// where this seems ok:

declare var d:string|number // or `'a'|number`

if (typeof d == 'string') { // or `if (d == 'a')`
    d // Type: string           // Type: 'a'
}
else {
    d // Type: number
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions