-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosThis issue has compiler-backed repros: https://aka.ms/ts-repros
Milestone
Description
Bug 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 Number, enum, and boolean literal types #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 #9407 (comment):
// 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;
}
Related issues
Rudxain
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosThis issue has compiler-backed repros: https://aka.ms/ts-repros