1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
tests/cases/compiler/a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
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 'bigint' 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/a.ts (4 errors) ====
interface BigIntIndex<E> {
[index: bigint]: E; // should error
~~~~~
!!! error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
}
const arr: number[] = [1, 2, 3];
let num: number = arr[1];
num = arr["1"];
num = arr[1n]; // should error
~~
!!! error TS2538: Type '1n' cannot be used as an index type.
let key: keyof any; // should be type "string | number | symbol"
key = 123;
key = "abc";
key = Symbol();
key = 123n; // should error
~~~
!!! error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'.
// Show correct usage of bigint index: explicitly convert to string
const bigNum: bigint = 0n;
const typedArray = new Uint8Array(3);
typedArray[bigNum] = 0xAA; // should error
~~~~~~
!!! error TS2538: Type 'bigint' cannot be used as an index type.
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
==== 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'.
|