Skip to content

Useless compile error on triple-equal 1|2 against 0 #21724

Description

TypeScript Version: 2.7.1

Search Terms: infer, compare, equals

Code

typeT=[number]|[number,number];// now t.length has type 1|2lett: T;if(t!.length===0){// compile error: Operator '===' cannot be applied to types '1' and '0'}if(t!.length>100){// no compile error}if(t!.length===1-1){// no compile error}

Expected behavior:
No compile errors on any of these. It's plain inconsistent and not useful.

Actual behavior:
Compile error on t === 0 but not on other comparisons

Playground Link:
See above

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions