-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it
Description
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
number
not assignable to*
- has no overlap
- Issue Trade-offs in Control Flow Analysis #9998, why does initialization narrow type? #8513
🕗 Version & Regression Information
Started to appear from 4.3.0-beta
⏯ 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
Labels
Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it