Skip to content

Commit 2ea2f4f

Browse files
sandersnLongTengDaotypescript-bot
authored
Bigint constructor forbids object null undefined (microsoft#43204)
* Update es2020.bigint.d.ts * Update es2020.bigint.d.ts * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * add a test Co-authored-by: 龙腾道 <[email protected]> Co-authored-by: TypeScript Bot <[email protected]>
1 parent e44d39d commit 2ea2f4f

File tree

6 files changed

+142
-1
lines changed

6 files changed

+142
-1
lines changed

src/lib/es2020.bigint.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ interface BigInt {
101101
}
102102

103103
interface BigIntConstructor {
104-
(value?: any): bigint;
104+
(value: bigint | boolean | number | string): bigint;
105105
readonly prototype: BigInt;
106106

107107
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
tests/cases/conformance/es2020/constructBigint.ts(6,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'string | number | bigint | boolean'.
2+
tests/cases/conformance/es2020/constructBigint.ts(7,8): error TS2345: Argument of type '{ e: number; m: number; }' is not assignable to parameter of type 'string | number | bigint | boolean'.
3+
Type '{ e: number; m: number; }' is not assignable to type 'true'.
4+
tests/cases/conformance/es2020/constructBigint.ts(8,8): error TS2345: Argument of type 'null' is not assignable to parameter of type 'string | number | bigint | boolean'.
5+
tests/cases/conformance/es2020/constructBigint.ts(9,8): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string | number | bigint | boolean'.
6+
7+
8+
==== tests/cases/conformance/es2020/constructBigint.ts (4 errors) ====
9+
BigInt(1);
10+
BigInt(1n);
11+
BigInt("0");
12+
BigInt(false);
13+
14+
BigInt(Symbol());
15+
~~~~~~~~
16+
!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'string | number | bigint | boolean'.
17+
BigInt({ e: 1, m: 1 })
18+
~~~~~~~~~~~~~~
19+
!!! error TS2345: Argument of type '{ e: number; m: number; }' is not assignable to parameter of type 'string | number | bigint | boolean'.
20+
!!! error TS2345: Type '{ e: number; m: number; }' is not assignable to type 'true'.
21+
BigInt(null);
22+
~~~~
23+
!!! error TS2345: Argument of type 'null' is not assignable to parameter of type 'string | number | bigint | boolean'.
24+
BigInt(undefined)
25+
~~~~~~~~~
26+
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string | number | bigint | boolean'.
27+
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [constructBigint.ts]
2+
BigInt(1);
3+
BigInt(1n);
4+
BigInt("0");
5+
BigInt(false);
6+
7+
BigInt(Symbol());
8+
BigInt({ e: 1, m: 1 })
9+
BigInt(null);
10+
BigInt(undefined)
11+
12+
13+
14+
//// [constructBigint.js]
15+
"use strict";
16+
BigInt(1);
17+
BigInt(1n);
18+
BigInt("0");
19+
BigInt(false);
20+
BigInt(Symbol());
21+
BigInt({ e: 1, m: 1 });
22+
BigInt(null);
23+
BigInt(undefined);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== tests/cases/conformance/es2020/constructBigint.ts ===
2+
BigInt(1);
3+
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
4+
5+
BigInt(1n);
6+
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
7+
8+
BigInt("0");
9+
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
10+
11+
BigInt(false);
12+
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
13+
14+
BigInt(Symbol());
15+
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
16+
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --))
17+
18+
BigInt({ e: 1, m: 1 })
19+
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
20+
>e : Symbol(e, Decl(constructBigint.ts, 6, 8))
21+
>m : Symbol(m, Decl(constructBigint.ts, 6, 14))
22+
23+
BigInt(null);
24+
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
25+
26+
BigInt(undefined)
27+
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
28+
>undefined : Symbol(undefined)
29+
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=== tests/cases/conformance/es2020/constructBigint.ts ===
2+
BigInt(1);
3+
>BigInt(1) : bigint
4+
>BigInt : BigIntConstructor
5+
>1 : 1
6+
7+
BigInt(1n);
8+
>BigInt(1n) : bigint
9+
>BigInt : BigIntConstructor
10+
>1n : 1n
11+
12+
BigInt("0");
13+
>BigInt("0") : bigint
14+
>BigInt : BigIntConstructor
15+
>"0" : "0"
16+
17+
BigInt(false);
18+
>BigInt(false) : bigint
19+
>BigInt : BigIntConstructor
20+
>false : false
21+
22+
BigInt(Symbol());
23+
>BigInt(Symbol()) : bigint
24+
>BigInt : BigIntConstructor
25+
>Symbol() : symbol
26+
>Symbol : SymbolConstructor
27+
28+
BigInt({ e: 1, m: 1 })
29+
>BigInt({ e: 1, m: 1 }) : bigint
30+
>BigInt : BigIntConstructor
31+
>{ e: 1, m: 1 } : { e: number; m: number; }
32+
>e : number
33+
>1 : 1
34+
>m : number
35+
>1 : 1
36+
37+
BigInt(null);
38+
>BigInt(null) : bigint
39+
>BigInt : BigIntConstructor
40+
>null : null
41+
42+
BigInt(undefined)
43+
>BigInt(undefined) : bigint
44+
>BigInt : BigIntConstructor
45+
>undefined : undefined
46+
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @target: esnext
2+
// @lib: esnext
3+
// @strict: true
4+
BigInt(1);
5+
BigInt(1n);
6+
BigInt("0");
7+
BigInt(false);
8+
9+
BigInt(Symbol());
10+
BigInt({ e: 1, m: 1 })
11+
BigInt(null);
12+
BigInt(undefined)
13+

0 commit comments

Comments
 (0)