Skip to content
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

Fixed accidental possibility to create Infinity/-Infinity number literal types #56301

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37259,6 +37259,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
switch (node.operand.kind) {
case SyntaxKind.NumericLiteral:
if (operandType === numberType) {
return numberType;
}
switch (node.operator) {
case SyntaxKind.MinusToken:
return getFreshTypeOfLiteralType(getNumberLiteralType(-(node.operand as NumericLiteral).text));
Expand Down
18 changes: 18 additions & 0 deletions tests/baselines/reference/noInfinityNumberLiterals.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/noInfinityNumberLiterals.ts] ////

=== noInfinityNumberLiterals.ts ===
type PositiveInfinity = 1e999;
>PositiveInfinity : Symbol(PositiveInfinity, Decl(noInfinityNumberLiterals.ts, 0, 0))

type NegativeInfinity = -1e999;
>NegativeInfinity : Symbol(NegativeInfinity, Decl(noInfinityNumberLiterals.ts, 0, 30), Decl(noInfinityNumberLiterals.ts, 5, 5))

const positiveInfinity = 1e999;
>positiveInfinity : Symbol(positiveInfinity, Decl(noInfinityNumberLiterals.ts, 3, 5))

const positiveInfinity2 = +1e999;
>positiveInfinity2 : Symbol(positiveInfinity2, Decl(noInfinityNumberLiterals.ts, 4, 5))

const NegativeInfinity = -1e999;
>NegativeInfinity : Symbol(NegativeInfinity, Decl(noInfinityNumberLiterals.ts, 0, 30), Decl(noInfinityNumberLiterals.ts, 5, 5))

25 changes: 25 additions & 0 deletions tests/baselines/reference/noInfinityNumberLiterals.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/noInfinityNumberLiterals.ts] ////

=== noInfinityNumberLiterals.ts ===
type PositiveInfinity = 1e999;
>PositiveInfinity : number

type NegativeInfinity = -1e999;
>NegativeInfinity : number
>-1e999 : number
>1e999 : number

const positiveInfinity = 1e999;
>positiveInfinity : number
>1e999 : number

const positiveInfinity2 = +1e999;
>positiveInfinity2 : number
>+1e999 : number
>1e999 : number

const NegativeInfinity = -1e999;
>NegativeInfinity : number
>-1e999 : number
>1e999 : number

9 changes: 9 additions & 0 deletions tests/cases/compiler/noInfinityNumberLiterals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @strict: true
// @noEmit: true

type PositiveInfinity = 1e999;
type NegativeInfinity = -1e999;

const positiveInfinity = 1e999;
const positiveInfinity2 = +1e999;
const NegativeInfinity = -1e999;
Loading