Skip to content

Commit 5f46d42

Browse files
authored
Error on missing BigInt in es2020 (microsoft#37899)
* Error on missing BigInt in ES2020 too. Previously it was only on ESNext, but bigint ships in ES 2020. There are no tests for this; passing `false` doesn't cause any tests to fail at least. * add tests
1 parent eb105ef commit 5f46d42

15 files changed

+187
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10358,7 +10358,7 @@ namespace ts {
1035810358
t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(<IntersectionType>t) :
1035910359
t.flags & TypeFlags.StringLike ? globalStringType :
1036010360
t.flags & TypeFlags.NumberLike ? globalNumberType :
10361-
t.flags & TypeFlags.BigIntLike ? getGlobalBigIntType(/*reportErrors*/ languageVersion >= ScriptTarget.ESNext) :
10361+
t.flags & TypeFlags.BigIntLike ? getGlobalBigIntType(/*reportErrors*/ languageVersion >= ScriptTarget.ES2020) :
1036210362
t.flags & TypeFlags.BooleanLike ? globalBooleanType :
1036310363
t.flags & TypeFlags.ESSymbolLike ? getGlobalESSymbolType(/*reportErrors*/ languageVersion >= ScriptTarget.ES2015) :
1036410364
t.flags & TypeFlags.NonPrimitive ? emptyObjectType :
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [bigintMissingES2019.ts]
2+
declare function test<A, B extends A>(): void;
3+
4+
test<{t?: string}, object>();
5+
test<{t?: string}, bigint>();
6+
7+
// no error when bigint is used even when ES2020 lib is not present
8+
9+
10+
//// [bigintMissingES2019.js]
11+
test();
12+
test();
13+
// no error when bigint is used even when ES2020 lib is not present
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/es2020/bigintMissingES2019.ts ===
2+
declare function test<A, B extends A>(): void;
3+
>test : Symbol(test, Decl(bigintMissingES2019.ts, 0, 0))
4+
>A : Symbol(A, Decl(bigintMissingES2019.ts, 0, 22))
5+
>B : Symbol(B, Decl(bigintMissingES2019.ts, 0, 24))
6+
>A : Symbol(A, Decl(bigintMissingES2019.ts, 0, 22))
7+
8+
test<{t?: string}, object>();
9+
>test : Symbol(test, Decl(bigintMissingES2019.ts, 0, 0))
10+
>t : Symbol(t, Decl(bigintMissingES2019.ts, 2, 6))
11+
12+
test<{t?: string}, bigint>();
13+
>test : Symbol(test, Decl(bigintMissingES2019.ts, 0, 0))
14+
>t : Symbol(t, Decl(bigintMissingES2019.ts, 3, 6))
15+
16+
// no error when bigint is used even when ES2020 lib is not present
17+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/conformance/es2020/bigintMissingES2019.ts ===
2+
declare function test<A, B extends A>(): void;
3+
>test : <A, B extends A>() => void
4+
5+
test<{t?: string}, object>();
6+
>test<{t?: string}, object>() : void
7+
>test : <A, B extends A>() => void
8+
>t : string
9+
10+
test<{t?: string}, bigint>();
11+
>test<{t?: string}, bigint>() : void
12+
>test : <A, B extends A>() => void
13+
>t : string
14+
15+
// no error when bigint is used even when ES2020 lib is not present
16+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error TS2318: Cannot find global type 'BigInt'.
2+
3+
4+
!!! error TS2318: Cannot find global type 'BigInt'.
5+
==== tests/cases/conformance/es2020/bigintMissingES2020.ts (0 errors) ====
6+
declare function test<A, B extends A>(): void;
7+
8+
test<{t?: string}, object>();
9+
test<{t?: string}, bigint>();
10+
11+
// should have global error when bigint is used but ES2020 lib is not present
12+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [bigintMissingES2020.ts]
2+
declare function test<A, B extends A>(): void;
3+
4+
test<{t?: string}, object>();
5+
test<{t?: string}, bigint>();
6+
7+
// should have global error when bigint is used but ES2020 lib is not present
8+
9+
10+
//// [bigintMissingES2020.js]
11+
test();
12+
test();
13+
// should have global error when bigint is used but ES2020 lib is not present
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/es2020/bigintMissingES2020.ts ===
2+
declare function test<A, B extends A>(): void;
3+
>test : Symbol(test, Decl(bigintMissingES2020.ts, 0, 0))
4+
>A : Symbol(A, Decl(bigintMissingES2020.ts, 0, 22))
5+
>B : Symbol(B, Decl(bigintMissingES2020.ts, 0, 24))
6+
>A : Symbol(A, Decl(bigintMissingES2020.ts, 0, 22))
7+
8+
test<{t?: string}, object>();
9+
>test : Symbol(test, Decl(bigintMissingES2020.ts, 0, 0))
10+
>t : Symbol(t, Decl(bigintMissingES2020.ts, 2, 6))
11+
12+
test<{t?: string}, bigint>();
13+
>test : Symbol(test, Decl(bigintMissingES2020.ts, 0, 0))
14+
>t : Symbol(t, Decl(bigintMissingES2020.ts, 3, 6))
15+
16+
// should have global error when bigint is used but ES2020 lib is not present
17+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/conformance/es2020/bigintMissingES2020.ts ===
2+
declare function test<A, B extends A>(): void;
3+
>test : <A, B extends A>() => void
4+
5+
test<{t?: string}, object>();
6+
>test<{t?: string}, object>() : void
7+
>test : <A, B extends A>() => void
8+
>t : string
9+
10+
test<{t?: string}, bigint>();
11+
>test<{t?: string}, bigint>() : void
12+
>test : <A, B extends A>() => void
13+
>t : string
14+
15+
// should have global error when bigint is used but ES2020 lib is not present
16+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error TS2318: Cannot find global type 'BigInt'.
2+
3+
4+
!!! error TS2318: Cannot find global type 'BigInt'.
5+
==== tests/cases/conformance/es2020/bigintMissingESNext.ts (0 errors) ====
6+
declare function test<A, B extends A>(): void;
7+
8+
test<{t?: string}, object>();
9+
test<{t?: string}, bigint>();
10+
11+
// should have global error when bigint is used but ES2020 lib is not present
12+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [bigintMissingESNext.ts]
2+
declare function test<A, B extends A>(): void;
3+
4+
test<{t?: string}, object>();
5+
test<{t?: string}, bigint>();
6+
7+
// should have global error when bigint is used but ES2020 lib is not present
8+
9+
10+
//// [bigintMissingESNext.js]
11+
test();
12+
test();
13+
// should have global error when bigint is used but ES2020 lib is not present
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/es2020/bigintMissingESNext.ts ===
2+
declare function test<A, B extends A>(): void;
3+
>test : Symbol(test, Decl(bigintMissingESNext.ts, 0, 0))
4+
>A : Symbol(A, Decl(bigintMissingESNext.ts, 0, 22))
5+
>B : Symbol(B, Decl(bigintMissingESNext.ts, 0, 24))
6+
>A : Symbol(A, Decl(bigintMissingESNext.ts, 0, 22))
7+
8+
test<{t?: string}, object>();
9+
>test : Symbol(test, Decl(bigintMissingESNext.ts, 0, 0))
10+
>t : Symbol(t, Decl(bigintMissingESNext.ts, 2, 6))
11+
12+
test<{t?: string}, bigint>();
13+
>test : Symbol(test, Decl(bigintMissingESNext.ts, 0, 0))
14+
>t : Symbol(t, Decl(bigintMissingESNext.ts, 3, 6))
15+
16+
// should have global error when bigint is used but ES2020 lib is not present
17+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/conformance/es2020/bigintMissingESNext.ts ===
2+
declare function test<A, B extends A>(): void;
3+
>test : <A, B extends A>() => void
4+
5+
test<{t?: string}, object>();
6+
>test<{t?: string}, object>() : void
7+
>test : <A, B extends A>() => void
8+
>t : string
9+
10+
test<{t?: string}, bigint>();
11+
>test<{t?: string}, bigint>() : void
12+
>test : <A, B extends A>() => void
13+
>t : string
14+
15+
// should have global error when bigint is used but ES2020 lib is not present
16+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: es2019
2+
// @lib: dom,es2019
3+
declare function test<A, B extends A>(): void;
4+
5+
test<{t?: string}, object>();
6+
test<{t?: string}, bigint>();
7+
8+
// no error when bigint is used even when ES2020 lib is not present
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: es2020
2+
// @lib: dom,es2017
3+
declare function test<A, B extends A>(): void;
4+
5+
test<{t?: string}, object>();
6+
test<{t?: string}, bigint>();
7+
8+
// should have global error when bigint is used but ES2020 lib is not present
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: esnext
2+
// @lib: dom,es2017
3+
declare function test<A, B extends A>(): void;
4+
5+
test<{t?: string}, object>();
6+
test<{t?: string}, bigint>();
7+
8+
// should have global error when bigint is used but ES2020 lib is not present

0 commit comments

Comments
 (0)