Skip to content

Commit ecd1245

Browse files
committed
Add test for bigint property
1 parent 6f97fb5 commit ecd1245

File tree

5 files changed

+122
-36
lines changed

5 files changed

+122
-36
lines changed

Diff for: tests/baselines/reference/bigintIndex.errors.txt

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
tests/cases/compiler/bigintIndex.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
2-
tests/cases/compiler/bigintIndex.ts(8,11): error TS2538: Type '1n' cannot be used as an index type.
3-
tests/cases/compiler/bigintIndex.ts(14,1): error TS2322: Type '123n' is not assignable to type 'string | number | symbol'.
4-
tests/cases/compiler/bigintIndex.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type.
1+
tests/cases/compiler/a.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
2+
tests/cases/compiler/a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type.
3+
tests/cases/compiler/a.ts(14,1): error TS2322: Type '123n' is not assignable to type 'string | number | symbol'.
4+
tests/cases/compiler/a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type.
5+
tests/cases/compiler/b.ts(2,12): error TS1136: Property assignment expected.
6+
tests/cases/compiler/b.ts(2,14): error TS1005: ';' expected.
7+
tests/cases/compiler/b.ts(2,19): error TS1128: Declaration or statement expected.
8+
tests/cases/compiler/b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
9+
tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
510

611

7-
==== tests/cases/compiler/bigintIndex.ts (4 errors) ====
12+
==== tests/cases/compiler/a.ts (4 errors) ====
813
interface BigIntIndex<E> {
914
[index: bigint]: E; // should error
1015
~~~~~
@@ -34,4 +39,21 @@ tests/cases/compiler/bigintIndex.ts(19,12): error TS2538: Type 'bigint' cannot b
3439
!!! error TS2538: Type 'bigint' cannot be used as an index type.
3540
typedArray[String(bigNum)] = 0xAA;
3641
typedArray["1"] = 0xBB;
37-
typedArray[2] = 0xCC;
42+
typedArray[2] = 0xCC;
43+
44+
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
45+
==== tests/cases/compiler/b.ts (5 errors) ====
46+
// BigInt cannot be used as an object literal property
47+
const a = {1n: 123};
48+
~~
49+
!!! error TS1136: Property assignment expected.
50+
~
51+
!!! error TS1005: ';' expected.
52+
~
53+
!!! error TS1128: Declaration or statement expected.
54+
const b = {[1n]: 456};
55+
~~~~
56+
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
57+
const c = {[bigNum]: 789};
58+
~~~~~~~~
59+
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.

Diff for: tests/baselines/reference/bigintIndex.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//// [bigintIndex.ts]
1+
//// [tests/cases/compiler/bigintIndex.ts] ////
2+
3+
//// [a.ts]
24
interface BigIntIndex<E> {
35
[index: bigint]: E; // should error
46
}
@@ -20,9 +22,16 @@ const typedArray = new Uint8Array(3);
2022
typedArray[bigNum] = 0xAA; // should error
2123
typedArray[String(bigNum)] = 0xAA;
2224
typedArray["1"] = 0xBB;
23-
typedArray[2] = 0xCC;
25+
typedArray[2] = 0xCC;
26+
27+
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
28+
//// [b.ts]
29+
// BigInt cannot be used as an object literal property
30+
const a = {1n: 123};
31+
const b = {[1n]: 456};
32+
const c = {[bigNum]: 789};
2433

25-
//// [bigintIndex.js]
34+
//// [a.js]
2635
const arr = [1, 2, 3];
2736
let num = arr[1];
2837
num = arr["1"];
@@ -39,3 +48,12 @@ typedArray[bigNum] = 0xAA; // should error
3948
typedArray[String(bigNum)] = 0xAA;
4049
typedArray["1"] = 0xBB;
4150
typedArray[2] = 0xCC;
51+
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
52+
//// [b.js]
53+
// BigInt cannot be used as an object literal property
54+
const a = {};
55+
1n;
56+
123;
57+
;
58+
const b = { [1n]: 456 };
59+
const c = { [bigNum]: 789 };

Diff for: tests/baselines/reference/bigintIndex.symbols

+40-25
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,79 @@
1-
=== tests/cases/compiler/bigintIndex.ts ===
1+
=== tests/cases/compiler/a.ts ===
22
interface BigIntIndex<E> {
3-
>BigIntIndex : Symbol(BigIntIndex, Decl(bigintIndex.ts, 0, 0))
4-
>E : Symbol(E, Decl(bigintIndex.ts, 0, 22))
3+
>BigIntIndex : Symbol(BigIntIndex, Decl(a.ts, 0, 0))
4+
>E : Symbol(E, Decl(a.ts, 0, 22))
55

66
[index: bigint]: E; // should error
7-
>index : Symbol(index, Decl(bigintIndex.ts, 1, 5))
8-
>E : Symbol(E, Decl(bigintIndex.ts, 0, 22))
7+
>index : Symbol(index, Decl(a.ts, 1, 5))
8+
>E : Symbol(E, Decl(a.ts, 0, 22))
99
}
1010

1111
const arr: number[] = [1, 2, 3];
12-
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
12+
>arr : Symbol(arr, Decl(a.ts, 4, 5))
1313

1414
let num: number = arr[1];
15-
>num : Symbol(num, Decl(bigintIndex.ts, 5, 3))
16-
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
15+
>num : Symbol(num, Decl(a.ts, 5, 3))
16+
>arr : Symbol(arr, Decl(a.ts, 4, 5))
1717

1818
num = arr["1"];
19-
>num : Symbol(num, Decl(bigintIndex.ts, 5, 3))
20-
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
19+
>num : Symbol(num, Decl(a.ts, 5, 3))
20+
>arr : Symbol(arr, Decl(a.ts, 4, 5))
2121

2222
num = arr[1n]; // should error
23-
>num : Symbol(num, Decl(bigintIndex.ts, 5, 3))
24-
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
23+
>num : Symbol(num, Decl(a.ts, 5, 3))
24+
>arr : Symbol(arr, Decl(a.ts, 4, 5))
2525

2626
let key: keyof any; // should be type "string | number | symbol"
27-
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
27+
>key : Symbol(key, Decl(a.ts, 9, 3))
2828

2929
key = 123;
30-
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
30+
>key : Symbol(key, Decl(a.ts, 9, 3))
3131

3232
key = "abc";
33-
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
33+
>key : Symbol(key, Decl(a.ts, 9, 3))
3434

3535
key = Symbol();
36-
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
36+
>key : Symbol(key, Decl(a.ts, 9, 3))
3737
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.symbol.d.ts, --, --))
3838

3939
key = 123n; // should error
40-
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
40+
>key : Symbol(key, Decl(a.ts, 9, 3))
4141

4242
// Show correct usage of bigint index: explicitly convert to string
4343
const bigNum: bigint = 0n;
44-
>bigNum : Symbol(bigNum, Decl(bigintIndex.ts, 16, 5))
44+
>bigNum : Symbol(bigNum, Decl(a.ts, 16, 5))
4545

4646
const typedArray = new Uint8Array(3);
47-
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
47+
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
4848
>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
4949

5050
typedArray[bigNum] = 0xAA; // should error
51-
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
52-
>bigNum : Symbol(bigNum, Decl(bigintIndex.ts, 16, 5))
51+
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
52+
>bigNum : Symbol(bigNum, Decl(a.ts, 16, 5))
5353

5454
typedArray[String(bigNum)] = 0xAA;
55-
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
55+
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
5656
>String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --) ... and 2 more)
57-
>bigNum : Symbol(bigNum, Decl(bigintIndex.ts, 16, 5))
57+
>bigNum : Symbol(bigNum, Decl(a.ts, 16, 5))
5858

5959
typedArray["1"] = 0xBB;
60-
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
60+
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
6161

6262
typedArray[2] = 0xCC;
63-
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
63+
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
64+
65+
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
66+
=== tests/cases/compiler/b.ts ===
67+
// BigInt cannot be used as an object literal property
68+
const a = {1n: 123};
69+
>a : Symbol(a, Decl(b.ts, 1, 5))
70+
71+
const b = {[1n]: 456};
72+
>b : Symbol(b, Decl(b.ts, 2, 5))
73+
>[1n] : Symbol([1n], Decl(b.ts, 2, 11))
74+
75+
const c = {[bigNum]: 789};
76+
>c : Symbol(c, Decl(b.ts, 3, 5))
77+
>[bigNum] : Symbol([bigNum], Decl(b.ts, 3, 11))
78+
>bigNum : Symbol(bigNum, Decl(a.ts, 16, 5))
6479

Diff for: tests/baselines/reference/bigintIndex.types

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
=== tests/cases/compiler/bigintIndex.ts ===
1+
=== tests/cases/compiler/a.ts ===
22
interface BigIntIndex<E> {
33
[index: bigint]: E; // should error
44
>index : bigint
@@ -96,3 +96,26 @@ typedArray[2] = 0xCC;
9696
>2 : 2
9797
>0xCC : 204
9898

99+
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
100+
=== tests/cases/compiler/b.ts ===
101+
// BigInt cannot be used as an object literal property
102+
const a = {1n: 123};
103+
>a : {}
104+
>{ : {}
105+
>1n : 1n
106+
>123 : 123
107+
108+
const b = {[1n]: 456};
109+
>b : {}
110+
>{[1n]: 456} : {}
111+
>[1n] : number
112+
>1n : 1n
113+
>456 : 456
114+
115+
const c = {[bigNum]: 789};
116+
>c : {}
117+
>{[bigNum]: 789} : {}
118+
>[bigNum] : number
119+
>bigNum : bigint
120+
>789 : 789
121+

Diff for: tests/cases/compiler/bigintIndex.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @target: esnext
22
// @experimentalBigInt: true
33

4+
// @filename: a.ts
45
interface BigIntIndex<E> {
56
[index: bigint]: E; // should error
67
}
@@ -22,4 +23,11 @@ const typedArray = new Uint8Array(3);
2223
typedArray[bigNum] = 0xAA; // should error
2324
typedArray[String(bigNum)] = 0xAA;
2425
typedArray["1"] = 0xBB;
25-
typedArray[2] = 0xCC;
26+
typedArray[2] = 0xCC;
27+
28+
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
29+
// @filename: b.ts
30+
// BigInt cannot be used as an object literal property
31+
const a = {1n: 123};
32+
const b = {[1n]: 456};
33+
const c = {[bigNum]: 789};

0 commit comments

Comments
 (0)