Skip to content

Commit e56d3c9

Browse files
committed
Fixed accidental possibility to create Infinity/-Infinity number literal types
1 parent 73bc0eb commit e56d3c9

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

src/compiler/checker.ts

+3
Original file line numberDiff line numberDiff line change
@@ -37259,6 +37259,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3725937259
}
3726037260
switch (node.operand.kind) {
3726137261
case SyntaxKind.NumericLiteral:
37262+
if (operandType === numberType) {
37263+
return numberType;
37264+
}
3726237265
switch (node.operator) {
3726337266
case SyntaxKind.MinusToken:
3726437267
return getFreshTypeOfLiteralType(getNumberLiteralType(-(node.operand as NumericLiteral).text));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/noInfinityNumberLiterals.ts] ////
2+
3+
=== noInfinityNumberLiterals.ts ===
4+
type PositiveInfinity = 1e999;
5+
>PositiveInfinity : Symbol(PositiveInfinity, Decl(noInfinityNumberLiterals.ts, 0, 0))
6+
7+
type NegativeInfinity = -1e999;
8+
>NegativeInfinity : Symbol(NegativeInfinity, Decl(noInfinityNumberLiterals.ts, 0, 30), Decl(noInfinityNumberLiterals.ts, 5, 5))
9+
10+
const positiveInfinity = 1e999;
11+
>positiveInfinity : Symbol(positiveInfinity, Decl(noInfinityNumberLiterals.ts, 3, 5))
12+
13+
const positiveInfinity2 = +1e999;
14+
>positiveInfinity2 : Symbol(positiveInfinity2, Decl(noInfinityNumberLiterals.ts, 4, 5))
15+
16+
const NegativeInfinity = -1e999;
17+
>NegativeInfinity : Symbol(NegativeInfinity, Decl(noInfinityNumberLiterals.ts, 0, 30), Decl(noInfinityNumberLiterals.ts, 5, 5))
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/compiler/noInfinityNumberLiterals.ts] ////
2+
3+
=== noInfinityNumberLiterals.ts ===
4+
type PositiveInfinity = 1e999;
5+
>PositiveInfinity : number
6+
7+
type NegativeInfinity = -1e999;
8+
>NegativeInfinity : number
9+
>-1e999 : number
10+
>1e999 : number
11+
12+
const positiveInfinity = 1e999;
13+
>positiveInfinity : number
14+
>1e999 : number
15+
16+
const positiveInfinity2 = +1e999;
17+
>positiveInfinity2 : number
18+
>+1e999 : number
19+
>1e999 : number
20+
21+
const NegativeInfinity = -1e999;
22+
>NegativeInfinity : number
23+
>-1e999 : number
24+
>1e999 : number
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
type PositiveInfinity = 1e999;
5+
type NegativeInfinity = -1e999;
6+
7+
const positiveInfinity = 1e999;
8+
const positiveInfinity2 = +1e999;
9+
const NegativeInfinity = -1e999;

0 commit comments

Comments
 (0)