Broken emit when `Infinity` or `‑Infinity` ends up in a type position
See original GitHub issueBug Report
🔎 Search Terms
Infinity
NaN
- numeric
- literal
🕗 Version & Regression Information
- Tested in: TypeScript 4.1.5 and TypeScript 4.3.0‑dev
- I was unable to test this on prior versions because https://github.com/microsoft/TypeScript/pull/9407 was implemented in TypeScript 2.0.
💻 Code
// @declaration
// @showEmit
// @showEmittedFile: index.d.ts
// @filename: index.ts
export const PositiveInfinity: 1e1_000_000 = 1/0 as any;
export const NegativeInfinity: -1e1_000_000 = -1/0 as any;
⏯ Playground Link
🙁 Actual behavior
TypeScript emits Infinity
and ‑Infinity
in a type position, which are intentionally invalid according to https://github.com/microsoft/TypeScript/pull/9407#issuecomment-229721835:
// index.d.ts
export const PositiveInfinity: Infinity;
export const NegativeInfinity: -Infinity;
🙂 Expected behavior
The Infinity
and ‑Infinity
values are valid in a type position, so that the generated .d.ts
file is valid.
Also, it’d be nice to support literal NaN
s, which would allow for Number.isNaN
to be typed as:
interface NumberConstructor {
isNaN(number: unknown): number is NaN;
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Infinity & NaN Type-level Support #51741 - GitHub
Successfully merging this pull request may close these issues. Broken emit when Infinity or ‑Infinity ends up in a type position ...
Read more >Hydrogen's Atomic Emission Spectrum - Chemistry LibreTexts
This is known as its ground state. If enough energy is supplied to move the electron up to the infinity level, the atom...
Read more >atom - Orbits and energy levels | Britannica
An electron disappears from the orbit in which it is located and reappears in its new location without ever appearing any place in...
Read more >UNSC Infinity - Ship - Halopedia, the Halo wiki
UNSC Infinity is an experimental Infinity-class supercarrier of the UNSC Navy commissioned following the end of the Human-Covenant War.
Read more >3.5 Limits at Infinity, Infinite Limits and Asymptotes
If this limits exists, we say that the function f f has the limit L L as x x increases without bound. Similarly,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The example is bigint not number. BigInts don’t contain an
Infinity
value, I think it’s a lot more readable to use the explicitInfinity
value rather than some arbitrary token as it already compares correctly with bigints (e.g.bigint < Infinity
is alwaystrue
, no coercion toNumber
happens).You’re mixing a bug report and a feature request together in one. Fixing the bug would be to emit the type
number
instead ofInfinity
. Introducing anInfinity
(andNaN
) type is a feature request, for which you should provide a good reasoning in response to https://github.com/microsoft/TypeScript/pull/9407#issuecomment-229721835.