-
Notifications
You must be signed in to change notification settings - Fork 12.8k
tsc gets confused on checking assignability with numeric literals? #44087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This seems likely to be a side effect of having fixed #42442. |
cc @ahejlsberg and @DanielRosenwasser for ideas on how to fix this 😕 |
Ugh. We permit the assignment of We need to somehow exclude the number-assignable-to-any-enum rule from our control flow analysis. Ideally CFA sould view the initialization as having an unknown effect, thus not narrowing at all following the initialization. |
I would honestly propose Won't Fix and recommend writing const abc = param as (A | -1); instead since the assignment is already unsound. Piling up the epicycles higher will probably only make things worse. |
The disallowment of Fixing the narrowing would be very invasive and noisy; we're going to leave this as-is. |
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 ofabc
(A | -1
) in , becausenumber
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*
🕗 Version & Regression Information
Started to appear from
4.3.0-beta
⏯ Playground Link
Playground link
💻 Code
🙁 Actual behavior
TSC complains that
abc
cannot be-1
🙂 Expected behavior
TSC is happy
The text was updated successfully, but these errors were encountered: