Skip to content

Broken emit when Infinity or ‑Infinity ends up in a type position #42905

@ExE-Boss

Description

@ExE-Boss

Bug Report

🔎 Search Terms

  • Infinity
  • NaN
  • numeric
  • literal

🕗 Version & Regression Information

💻 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

Workbench Repro

🙁 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 NaNs, which would allow for Number.isNaN to be typed as:

interface NumberConstructor {
	isNaN(number: unknown): number is NaN;
}

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-repros

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions