Unable to include a literal NaN
, Infinity
, or -Infinity
in a union type
#47347
Labels
Duplicate
An existing issue was already created
Bug Report
See the link below. I want to define a function as returning either
NaN
,1
,2
, or3
. I can do1 | 2 | 3
, but TS errors when I doNaN | 1 | 2 | 3
, and if i dotypeof NaN
it allows any number.⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The
c
declaration errors, and thez
assignment does not fail.🙂 Expected behavior
The
c
declaration works, and thez
assignment should fail. Why? BecauseNaN
and the Infinities are just as much a number as1
and2
are, and I want to correctly type my API.The text was updated successfully, but these errors were encountered: