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
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
-1from the union type annotation ofabc(A | -1) in , becausenumberis 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
numbernot assignable to*🕗 Version & Regression Information
Started to appear from
4.3.0-beta⏯ Playground Link
Playground link
💻 Code
🙁 Actual behavior
TSC complains that
abccannot be-1🙂 Expected behavior
TSC is happy