mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
42 lines
1.7 KiB
Plaintext
42 lines
1.7 KiB
Plaintext
a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
|
|
a.ts(8,11): error TS2538: Type 'bigint' cannot be used as an index type.
|
|
a.ts(9,17): error TS2538: Type 'bigint' cannot be used as an index type.
|
|
a.ts(15,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'.
|
|
a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type.
|
|
|
|
|
|
==== a.ts (5 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 'bigint' cannot be used as an index type.
|
|
num = [1, 2, 3][1n]; // should error
|
|
~~
|
|
!!! error TS2538: Type 'bigint' 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;
|
|
|