8000 tsc gets confused on checking assignability with numeric literals? · Issue #44087 · microsoft/TypeScript · GitHub 8000
[go: up one dir, main page]

Skip to content
tsc gets confused on checking assignability with numeric literals? #44087
@h-joo

Description

@h-joo

Bug Report

TSC reports This condition will always return 'false' since the types 'A' and '-1' have no overlap.

For a moment I thought this might be another instance of #9998 or #8513, but from my understanding, the compiler ignores the -1 from the union type annotation of abc(A | -1) in , because number is not assignable to -1. So I thought this might be a different issue from #9998 or #8513, since the core issue seems to be that a literal type within a union expression gets ignored.

🔎 Search Terms

🕗 Version & Regression Information

Started to appear from 4.3.0-beta

⏯ Playground Link

Playground link

💻 Code

enum A{
    A0 = 0,    
    A1 = 1,
}
function foo(param:number) {
    const abc : (A | -1) = param;
    if(abc === -1) {
       ~~~~~~~~~ This condition will always return 'false' since the types 'A' and '-1' have no overlap.        
    }
}

🙁 Actual behavior

TSC complains that abc cannot be -1

🙂 Expected behavior

TSC is happy

Metadata

Metadata

Assignees

No one assigned

    Labels

    Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0