Add test for bigint property

This commit is contained in:
Caleb Sander 2018-11-02 21:32:43 -07:00
parent 6f97fb5f02
commit ecd12453f4
5 changed files with 122 additions and 36 deletions

View File

@ -1,10 +1,15 @@
tests/cases/compiler/bigintIndex.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
tests/cases/compiler/bigintIndex.ts(8,11): error TS2538: Type '1n' cannot be used as an index type.
tests/cases/compiler/bigintIndex.ts(14,1): error TS2322: Type '123n' is not assignable to type 'string | number | symbol'.
tests/cases/compiler/bigintIndex.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type.
tests/cases/compiler/a.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
tests/cases/compiler/a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type.
tests/cases/compiler/a.ts(14,1): error TS2322: Type '123n' is not assignable to type 'string | number | symbol'.
tests/cases/compiler/a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type.
tests/cases/compiler/b.ts(2,12): error TS1136: Property assignment expected.
tests/cases/compiler/b.ts(2,14): error TS1005: ';' expected.
tests/cases/compiler/b.ts(2,19): error TS1128: Declaration or statement expected.
tests/cases/compiler/b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
==== tests/cases/compiler/bigintIndex.ts (4 errors) ====
==== tests/cases/compiler/a.ts (4 errors) ====
interface BigIntIndex<E> {
[index: bigint]: E; // should error
~~~~~
@ -34,4 +39,21 @@ tests/cases/compiler/bigintIndex.ts(19,12): error TS2538: Type 'bigint' cannot b
!!! error TS2538: Type 'bigint' cannot be used as an index type.
typedArray[String(bigNum)] = 0xAA;
typedArray["1"] = 0xBB;
typedArray[2] = 0xCC;
typedArray[2] = 0xCC;
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
==== tests/cases/compiler/b.ts (5 errors) ====
// BigInt cannot be used as an object literal property
const a = {1n: 123};
~~
!!! error TS1136: Property assignment expected.
~
!!! error TS1005: ';' expected.
~
!!! error TS1128: Declaration or statement expected.
const b = {[1n]: 456};
~~~~
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
const c = {[bigNum]: 789};
~~~~~~~~
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.

View File

@ -1,4 +1,6 @@
//// [bigintIndex.ts]
//// [tests/cases/compiler/bigintIndex.ts] ////
//// [a.ts]
interface BigIntIndex<E> {
[index: bigint]: E; // should error
}
@ -20,9 +22,16 @@ const typedArray = new Uint8Array(3);
typedArray[bigNum] = 0xAA; // should error
typedArray[String(bigNum)] = 0xAA;
typedArray["1"] = 0xBB;
typedArray[2] = 0xCC;
typedArray[2] = 0xCC;
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
//// [b.ts]
// BigInt cannot be used as an object literal property
const a = {1n: 123};
const b = {[1n]: 456};
const c = {[bigNum]: 789};
//// [bigintIndex.js]
//// [a.js]
const arr = [1, 2, 3];
let num = arr[1];
num = arr["1"];
@ -39,3 +48,12 @@ typedArray[bigNum] = 0xAA; // should error
typedArray[String(bigNum)] = 0xAA;
typedArray["1"] = 0xBB;
typedArray[2] = 0xCC;
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
//// [b.js]
// BigInt cannot be used as an object literal property
const a = {};
1n;
123;
;
const b = { [1n]: 456 };
const c = { [bigNum]: 789 };

View File

@ -1,64 +1,79 @@
=== tests/cases/compiler/bigintIndex.ts ===
=== tests/cases/compiler/a.ts ===
interface BigIntIndex<E> {
>BigIntIndex : Symbol(BigIntIndex, Decl(bigintIndex.ts, 0, 0))
>E : Symbol(E, Decl(bigintIndex.ts, 0, 22))
>BigIntIndex : Symbol(BigIntIndex, Decl(a.ts, 0, 0))
>E : Symbol(E, Decl(a.ts, 0, 22))
[index: bigint]: E; // should error
>index : Symbol(index, Decl(bigintIndex.ts, 1, 5))
>E : Symbol(E, Decl(bigintIndex.ts, 0, 22))
>index : Symbol(index, Decl(a.ts, 1, 5))
>E : Symbol(E, Decl(a.ts, 0, 22))
}
const arr: number[] = [1, 2, 3];
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
>arr : Symbol(arr, Decl(a.ts, 4, 5))
let num: number = arr[1];
>num : Symbol(num, Decl(bigintIndex.ts, 5, 3))
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
>num : Symbol(num, Decl(a.ts, 5, 3))
>arr : Symbol(arr, Decl(a.ts, 4, 5))
num = arr["1"];
>num : Symbol(num, Decl(bigintIndex.ts, 5, 3))
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
>num : Symbol(num, Decl(a.ts, 5, 3))
>arr : Symbol(arr, Decl(a.ts, 4, 5))
num = arr[1n]; // should error
>num : Symbol(num, Decl(bigintIndex.ts, 5, 3))
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
>num : Symbol(num, Decl(a.ts, 5, 3))
>arr : Symbol(arr, Decl(a.ts, 4, 5))
let key: keyof any; // should be type "string | number | symbol"
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
>key : Symbol(key, Decl(a.ts, 9, 3))
key = 123;
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
>key : Symbol(key, Decl(a.ts, 9, 3))
key = "abc";
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
>key : Symbol(key, Decl(a.ts, 9, 3))
key = Symbol();
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
>key : Symbol(key, Decl(a.ts, 9, 3))
>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, --, --))
key = 123n; // should error
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
>key : Symbol(key, Decl(a.ts, 9, 3))
// Show correct usage of bigint index: explicitly convert to string
const bigNum: bigint = 0n;
>bigNum : Symbol(bigNum, Decl(bigintIndex.ts, 16, 5))
>bigNum : Symbol(bigNum, Decl(a.ts, 16, 5))
const typedArray = new Uint8Array(3);
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
>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, --, --))
typedArray[bigNum] = 0xAA; // should error
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
>bigNum : Symbol(bigNum, Decl(bigintIndex.ts, 16, 5))
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
>bigNum : Symbol(bigNum, Decl(a.ts, 16, 5))
typedArray[String(bigNum)] = 0xAA;
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
>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)
>bigNum : Symbol(bigNum, Decl(bigintIndex.ts, 16, 5))
>bigNum : Symbol(bigNum, Decl(a.ts, 16, 5))
typedArray["1"] = 0xBB;
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
typedArray[2] = 0xCC;
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
>typedArray : Symbol(typedArray, Decl(a.ts, 17, 5))
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
=== tests/cases/compiler/b.ts ===
// BigInt cannot be used as an object literal property
const a = {1n: 123};
>a : Symbol(a, Decl(b.ts, 1, 5))
const b = {[1n]: 456};
>b : Symbol(b, Decl(b.ts, 2, 5))
>[1n] : Symbol([1n], Decl(b.ts, 2, 11))
const c = {[bigNum]: 789};
>c : Symbol(c, Decl(b.ts, 3, 5))
>[bigNum] : Symbol([bigNum], Decl(b.ts, 3, 11))
>bigNum : Symbol(bigNum, Decl(a.ts, 16, 5))

View File

@ -1,4 +1,4 @@
=== tests/cases/compiler/bigintIndex.ts ===
=== tests/cases/compiler/a.ts ===
interface BigIntIndex<E> {
[index: bigint]: E; // should error
>index : bigint
@ -96,3 +96,26 @@ typedArray[2] = 0xCC;
>2 : 2
>0xCC : 204
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
=== tests/cases/compiler/b.ts ===
// BigInt cannot be used as an object literal property
const a = {1n: 123};
>a : {}
>{ : {}
>1n : 1n
>123 : 123
const b = {[1n]: 456};
>b : {}
>{[1n]: 456} : {}
>[1n] : number
>1n : 1n
>456 : 456
const c = {[bigNum]: 789};
>c : {}
>{[bigNum]: 789} : {}
>[bigNum] : number
>bigNum : bigint
>789 : 789

View File

@ -1,6 +1,7 @@
// @target: esnext
// @experimentalBigInt: true
// @filename: a.ts
interface BigIntIndex<E> {
[index: bigint]: E; // should error
}
@ -22,4 +23,11 @@ const typedArray = new Uint8Array(3);
typedArray[bigNum] = 0xAA; // should error
typedArray[String(bigNum)] = 0xAA;
typedArray["1"] = 0xBB;
typedArray[2] = 0xCC;
typedArray[2] = 0xCC;
// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown
// @filename: b.ts
// BigInt cannot be used as an object literal property
const a = {1n: 123};
const b = {[1n]: 456};
const c = {[bigNum]: 789};