Skip to content

Add support for defining: string - 'a' (string minus string literal type) #12182

Closed
@normalser

Description

@normalser

#11587 allows us to do this:

function test(a: 'a' | string) {
    if (a == 'a') { 
        a // <- type: 'a'
    }
}

It would be great if the following could also work:

type Z = {type:'a',a:string}|{type:string,b:string}
function test(a: Z) {
    if (a.type == 'a') { 
        a // <- type: Z but ideally if it could be {type:'a',a:string}
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions