Add bigint tests

This commit is contained in:
Caleb Sander
2018-09-29 15:19:52 -07:00
parent 95c24c6c6a
commit a93131319e
30 changed files with 4372 additions and 11 deletions

View File

@@ -0,0 +1,37 @@
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/bigintIndex.ts (4 errors) ====
interface BigIntIndex<E> {
[index: bigint]: E; // should error
~~~~~
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
}
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 '123n' 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;

View File

@@ -0,0 +1,41 @@
//// [bigintIndex.ts]
interface BigIntIndex<E> {
[index: bigint]: E; // should error
}
const arr: number[] = [1, 2, 3];
let num: number = arr[1];
num = arr["1"];
num = arr[1n]; // should error
let key: keyof any; // should be type "string | number | symbol"
key = 123;
key = "abc";
key = Symbol();
key = 123n; // should error
// Show correct usage of bigint index: explicitly convert to string
const bigNum: bigint = 0n;
const typedArray = new Uint8Array(3);
typedArray[bigNum] = 0xAA; // should error
typedArray[String(bigNum)] = 0xAA;
typedArray["1"] = 0xBB;
typedArray[2] = 0xCC;
//// [bigintIndex.js]
const arr = [1, 2, 3];
let num = arr[1];
num = arr["1"];
num = arr[1n]; // should error
let key; // should be type "string | number | symbol"
key = 123;
key = "abc";
key = Symbol();
key = 123n; // should error
// Show correct usage of bigint index: explicitly convert to string
const bigNum = 0n;
const typedArray = new Uint8Array(3);
typedArray[bigNum] = 0xAA; // should error
typedArray[String(bigNum)] = 0xAA;
typedArray["1"] = 0xBB;
typedArray[2] = 0xCC;

View File

@@ -0,0 +1,64 @@
=== tests/cases/compiler/bigintIndex.ts ===
interface BigIntIndex<E> {
>BigIntIndex : Symbol(BigIntIndex, Decl(bigintIndex.ts, 0, 0))
>E : Symbol(E, Decl(bigintIndex.ts, 0, 22))
[index: bigint]: E; // should error
>index : Symbol(index, Decl(bigintIndex.ts, 1, 5))
>E : Symbol(E, Decl(bigintIndex.ts, 0, 22))
}
const arr: number[] = [1, 2, 3];
>arr : Symbol(arr, Decl(bigintIndex.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 = arr["1"];
>num : Symbol(num, Decl(bigintIndex.ts, 5, 3))
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
num = arr[1n]; // should error
>num : Symbol(num, Decl(bigintIndex.ts, 5, 3))
>arr : Symbol(arr, Decl(bigintIndex.ts, 4, 5))
let key: keyof any; // should be type "string | number | symbol"
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
key = 123;
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
key = "abc";
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
key = Symbol();
>key : Symbol(key, Decl(bigintIndex.ts, 9, 3))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
key = 123n; // should error
>key : Symbol(key, Decl(bigintIndex.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))
const typedArray = new Uint8Array(3);
>typedArray : Symbol(typedArray, Decl(bigintIndex.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, --, --))
typedArray[bigNum] = 0xAA; // should error
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
>bigNum : Symbol(bigNum, Decl(bigintIndex.ts, 16, 5))
typedArray[String(bigNum)] = 0xAA;
>typedArray : Symbol(typedArray, Decl(bigintIndex.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 1 more)
>bigNum : Symbol(bigNum, Decl(bigintIndex.ts, 16, 5))
typedArray["1"] = 0xBB;
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))
typedArray[2] = 0xCC;
>typedArray : Symbol(typedArray, Decl(bigintIndex.ts, 17, 5))

View File

@@ -0,0 +1,98 @@
=== tests/cases/compiler/bigintIndex.ts ===
interface BigIntIndex<E> {
[index: bigint]: E; // should error
>index : bigint
}
const arr: number[] = [1, 2, 3];
>arr : number[]
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3
let num: number = arr[1];
>num : number
>arr[1] : number
>arr : number[]
>1 : 1
num = arr["1"];
>num = arr["1"] : any
>num : number
>arr["1"] : any
>arr : number[]
>"1" : "1"
num = arr[1n]; // should error
>num = arr[1n] : any
>num : number
>arr[1n] : any
>arr : number[]
>1n : 1n
let key: keyof any; // should be type "string | number | symbol"
>key : string | number | symbol
key = 123;
>key = 123 : 123
>key : string | number | symbol
>123 : 123
key = "abc";
>key = "abc" : "abc"
>key : string | number | symbol
>"abc" : "abc"
key = Symbol();
>key = Symbol() : symbol
>key : string | number | symbol
>Symbol() : symbol
>Symbol : SymbolConstructor
key = 123n; // should error
>key = 123n : 123n
>key : string | number | symbol
>123n : 123n
// Show correct usage of bigint index: explicitly convert to string
const bigNum: bigint = 0n;
>bigNum : bigint
>0n : 0n
const typedArray = new Uint8Array(3);
>typedArray : Uint8Array
>new Uint8Array(3) : Uint8Array
>Uint8Array : Uint8ArrayConstructor
>3 : 3
typedArray[bigNum] = 0xAA; // should error
>typedArray[bigNum] = 0xAA : 170
>typedArray[bigNum] : any
>typedArray : Uint8Array
>bigNum : bigint
>0xAA : 170
typedArray[String(bigNum)] = 0xAA;
>typedArray[String(bigNum)] = 0xAA : 170
>typedArray[String(bigNum)] : any
>typedArray : Uint8Array
>String(bigNum) : string
>String : StringConstructor
>bigNum : bigint
>0xAA : 170
typedArray["1"] = 0xBB;
>typedArray["1"] = 0xBB : 187
>typedArray["1"] : any
>typedArray : Uint8Array
>"1" : "1"
>0xBB : 187
typedArray[2] = 0xCC;
>typedArray[2] = 0xCC : 204
>typedArray[2] : number
>typedArray : Uint8Array
>2 : 2
>0xCC : 204

View File

@@ -0,0 +1,77 @@
tests/cases/compiler/bigintWithLib.ts(4,1): error TS2350: Only a void function can be called with the 'new' keyword.
tests/cases/compiler/bigintWithLib.ts(16,33): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
Property 'byteLength' is missing in type 'number[]'.
tests/cases/compiler/bigintWithLib.ts(21,13): error TS2540: Cannot assign to 'length' because it is a constant or a read-only property.
tests/cases/compiler/bigintWithLib.ts(28,35): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
tests/cases/compiler/bigintWithLib.ts(33,13): error TS2540: Cannot assign to 'length' because it is a constant or a read-only property.
tests/cases/compiler/bigintWithLib.ts(40,25): error TS2345: Argument of type '-1' is not assignable to parameter of type 'bigint'.
tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '123' is not assignable to parameter of type 'bigint'.
==== tests/cases/compiler/bigintWithLib.ts (7 errors) ====
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
bigintVal = BigInt("456");
new BigInt(123); // should error
~~~~~~~~~~~~~~~
!!! error TS2350: Only a void function can be called with the 'new' keyword.
bigintVal = BigInt.asIntN(8, 0xFFFFn);
bigintVal = BigInt.asUintN(8, 0xFFFFn);
bigintVal = bigintVal.valueOf();
let stringVal: string = bigintVal.toString();
stringVal = bigintVal.toString(2);
stringVal = bigintVal.toLocaleString();
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
bigIntArray = new BigInt64Array(10);
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
bigIntArray = new BigInt64Array([1, 2, 3]); // should error
~~~~~~~~~
!!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
!!! error TS2345: Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
!!! error TS2345: Property 'byteLength' is missing in type 'number[]'.
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
let len: number = bigIntArray.length;
bigIntArray.length = 10; // should error
~~~~~~
!!! error TS2540: Cannot assign to 'length' because it is a constant or a read-only property.
let arrayBufferLike: ArrayBufferView = bigIntArray;
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
bigUintArray = new BigUint64Array(10);
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
bigUintArray = new BigUint64Array([1, 2, 3]); // should error
~~~~~~~~~
!!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
!!! error TS2345: Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
len = bigIntArray.length;
bigIntArray.length = 10; // should error
~~~~~~
!!! error TS2540: Cannot assign to 'length' because it is a constant or a read-only property.
arrayBufferLike = bigIntArray;
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
dataView.setBigInt64(1, -1n);
dataView.setBigInt64(1, -1n, true);
dataView.setBigInt64(1, -1); // should error
~~
!!! error TS2345: Argument of type '-1' is not assignable to parameter of type 'bigint'.
dataView.setBigUint64(2, 123n);
dataView.setBigUint64(2, 123n, true);
dataView.setBigUint64(2, 123); // should error
~~~
!!! error TS2345: Argument of type '123' is not assignable to parameter of type 'bigint'.
bigintVal = dataView.getBigInt64(1);
bigintVal = dataView.getBigInt64(1, true);
bigintVal = dataView.getBigUint64(2);
bigintVal = dataView.getBigUint64(2, true);

View File

@@ -0,0 +1,94 @@
//// [bigintWithLib.ts]
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
bigintVal = BigInt("456");
new BigInt(123); // should error
bigintVal = BigInt.asIntN(8, 0xFFFFn);
bigintVal = BigInt.asUintN(8, 0xFFFFn);
bigintVal = bigintVal.valueOf();
let stringVal: string = bigintVal.toString();
stringVal = bigintVal.toString(2);
stringVal = bigintVal.toLocaleString();
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
bigIntArray = new BigInt64Array(10);
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
bigIntArray = new BigInt64Array([1, 2, 3]); // should error
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
let len: number = bigIntArray.length;
bigIntArray.length = 10; // should error
let arrayBufferLike: ArrayBufferView = bigIntArray;
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
bigUintArray = new BigUint64Array(10);
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
bigUintArray = new BigUint64Array([1, 2, 3]); // should error
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
len = bigIntArray.length;
bigIntArray.length = 10; // should error
arrayBufferLike = bigIntArray;
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
dataView.setBigInt64(1, -1n);
dataView.setBigInt64(1, -1n, true);
dataView.setBigInt64(1, -1); // should error
dataView.setBigUint64(2, 123n);
dataView.setBigUint64(2, 123n, true);
dataView.setBigUint64(2, 123); // should error
bigintVal = dataView.getBigInt64(1);
bigintVal = dataView.getBigInt64(1, true);
bigintVal = dataView.getBigUint64(2);
bigintVal = dataView.getBigUint64(2, true);
//// [bigintWithLib.js]
// Test BigInt functions
let bigintVal = BigInt(123);
bigintVal = BigInt("456");
new BigInt(123); // should error
bigintVal = BigInt.asIntN(8, 0xFFFFn);
bigintVal = BigInt.asUintN(8, 0xFFFFn);
bigintVal = bigintVal.valueOf();
let stringVal = bigintVal.toString();
stringVal = bigintVal.toString(2);
stringVal = bigintVal.toLocaleString();
// Test BigInt64Array
let bigIntArray = new BigInt64Array();
bigIntArray = new BigInt64Array(10);
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
bigIntArray = new BigInt64Array([1, 2, 3]); // should error
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
let len = bigIntArray.length;
bigIntArray.length = 10; // should error
let arrayBufferLike = bigIntArray;
// Test BigUint64Array
let bigUintArray = new BigUint64Array();
bigUintArray = new BigUint64Array(10);
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
bigUintArray = new BigUint64Array([1, 2, 3]); // should error
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
len = bigIntArray.length;
bigIntArray.length = 10; // should error
arrayBufferLike = bigIntArray;
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
dataView.setBigInt64(1, -1n);
dataView.setBigInt64(1, -1n, true);
dataView.setBigInt64(1, -1); // should error
dataView.setBigUint64(2, 123n);
dataView.setBigUint64(2, 123n, true);
dataView.setBigUint64(2, 123); // should error
bigintVal = dataView.getBigInt64(1);
bigintVal = dataView.getBigInt64(1, true);
bigintVal = dataView.getBigUint64(2);
bigintVal = dataView.getBigUint64(2, true);

View File

@@ -0,0 +1,206 @@
=== tests/cases/compiler/bigintWithLib.ts ===
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>BigInt : Symbol(BigInt, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigintVal = BigInt("456");
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>BigInt : Symbol(BigInt, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
new BigInt(123); // should error
>BigInt : Symbol(BigInt, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigintVal = BigInt.asIntN(8, 0xFFFFn);
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>BigInt.asIntN : Symbol(BigIntConstructor.asIntN, Decl(lib.esnext.bigint.d.ts, --, --))
>BigInt : Symbol(BigInt, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>asIntN : Symbol(BigIntConstructor.asIntN, Decl(lib.esnext.bigint.d.ts, --, --))
bigintVal = BigInt.asUintN(8, 0xFFFFn);
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>BigInt.asUintN : Symbol(BigIntConstructor.asUintN, Decl(lib.esnext.bigint.d.ts, --, --))
>BigInt : Symbol(BigInt, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>asUintN : Symbol(BigIntConstructor.asUintN, Decl(lib.esnext.bigint.d.ts, --, --))
bigintVal = bigintVal.valueOf();
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>bigintVal.valueOf : Symbol(BigInt.valueOf, Decl(lib.esnext.bigint.d.ts, --, --))
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>valueOf : Symbol(BigInt.valueOf, Decl(lib.esnext.bigint.d.ts, --, --))
let stringVal: string = bigintVal.toString();
>stringVal : Symbol(stringVal, Decl(bigintWithLib.ts, 7, 3))
>bigintVal.toString : Symbol(BigInt.toString, Decl(lib.esnext.bigint.d.ts, --, --))
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>toString : Symbol(BigInt.toString, Decl(lib.esnext.bigint.d.ts, --, --))
stringVal = bigintVal.toString(2);
>stringVal : Symbol(stringVal, Decl(bigintWithLib.ts, 7, 3))
>bigintVal.toString : Symbol(BigInt.toString, Decl(lib.esnext.bigint.d.ts, --, --))
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>toString : Symbol(BigInt.toString, Decl(lib.esnext.bigint.d.ts, --, --))
stringVal = bigintVal.toLocaleString();
>stringVal : Symbol(stringVal, Decl(bigintWithLib.ts, 7, 3))
>bigintVal.toLocaleString : Symbol(BigInt.toLocaleString, Decl(lib.esnext.bigint.d.ts, --, --))
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>toLocaleString : Symbol(BigInt.toLocaleString, Decl(lib.esnext.bigint.d.ts, --, --))
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigIntArray = new BigInt64Array(10);
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigIntArray = new BigInt64Array([1, 2, 3]); // should error
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
let len: number = bigIntArray.length;
>len : Symbol(len, Decl(bigintWithLib.ts, 19, 3))
>bigIntArray.length : Symbol(BigInt64Array.length, Decl(lib.esnext.bigint.d.ts, --, --))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>length : Symbol(BigInt64Array.length, Decl(lib.esnext.bigint.d.ts, --, --))
bigIntArray.length = 10; // should error
>bigIntArray.length : Symbol(BigInt64Array.length, Decl(lib.esnext.bigint.d.ts, --, --))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>length : Symbol(BigInt64Array.length, Decl(lib.esnext.bigint.d.ts, --, --))
let arrayBufferLike: ArrayBufferView = bigIntArray;
>arrayBufferLike : Symbol(arrayBufferLike, Decl(bigintWithLib.ts, 21, 3))
>ArrayBufferView : Symbol(ArrayBufferView, Decl(lib.es5.d.ts, --, --))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithLib.ts, 24, 3))
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigUintArray = new BigUint64Array(10);
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithLib.ts, 24, 3))
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithLib.ts, 24, 3))
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigUintArray = new BigUint64Array([1, 2, 3]); // should error
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithLib.ts, 24, 3))
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithLib.ts, 24, 3))
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithLib.ts, 24, 3))
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithLib.ts, 24, 3))
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
len = bigIntArray.length;
>len : Symbol(len, Decl(bigintWithLib.ts, 19, 3))
>bigIntArray.length : Symbol(BigInt64Array.length, Decl(lib.esnext.bigint.d.ts, --, --))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>length : Symbol(BigInt64Array.length, Decl(lib.esnext.bigint.d.ts, --, --))
bigIntArray.length = 10; // should error
>bigIntArray.length : Symbol(BigInt64Array.length, Decl(lib.esnext.bigint.d.ts, --, --))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
>length : Symbol(BigInt64Array.length, Decl(lib.esnext.bigint.d.ts, --, --))
arrayBufferLike = bigIntArray;
>arrayBufferLike : Symbol(arrayBufferLike, Decl(bigintWithLib.ts, 21, 3))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithLib.ts, 12, 3))
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>DataView : Symbol(DataView, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
dataView.setBigInt64(1, -1n);
>dataView.setBigInt64 : Symbol(DataView.setBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>setBigInt64 : Symbol(DataView.setBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
dataView.setBigInt64(1, -1n, true);
>dataView.setBigInt64 : Symbol(DataView.setBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>setBigInt64 : Symbol(DataView.setBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
dataView.setBigInt64(1, -1); // should error
>dataView.setBigInt64 : Symbol(DataView.setBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>setBigInt64 : Symbol(DataView.setBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
dataView.setBigUint64(2, 123n);
>dataView.setBigUint64 : Symbol(DataView.setBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>setBigUint64 : Symbol(DataView.setBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))
dataView.setBigUint64(2, 123n, true);
>dataView.setBigUint64 : Symbol(DataView.setBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>setBigUint64 : Symbol(DataView.setBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))
dataView.setBigUint64(2, 123); // should error
>dataView.setBigUint64 : Symbol(DataView.setBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>setBigUint64 : Symbol(DataView.setBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))
bigintVal = dataView.getBigInt64(1);
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>dataView.getBigInt64 : Symbol(DataView.getBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>getBigInt64 : Symbol(DataView.getBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
bigintVal = dataView.getBigInt64(1, true);
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>dataView.getBigInt64 : Symbol(DataView.getBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>getBigInt64 : Symbol(DataView.getBigInt64, Decl(lib.esnext.bigint.d.ts, --, --))
bigintVal = dataView.getBigUint64(2);
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>dataView.getBigUint64 : Symbol(DataView.getBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>getBigUint64 : Symbol(DataView.getBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))
bigintVal = dataView.getBigUint64(2, true);
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
>dataView.getBigUint64 : Symbol(DataView.getBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))
>dataView : Symbol(dataView, Decl(bigintWithLib.ts, 36, 5))
>getBigUint64 : Symbol(DataView.getBigUint64, Decl(lib.esnext.bigint.d.ts, --, --))

View File

@@ -0,0 +1,334 @@
=== tests/cases/compiler/bigintWithLib.ts ===
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
>bigintVal : bigint
>BigInt(123) : bigint
>BigInt : BigIntConstructor
>123 : 123
bigintVal = BigInt("456");
>bigintVal = BigInt("456") : bigint
>bigintVal : bigint
>BigInt("456") : bigint
>BigInt : BigIntConstructor
>"456" : "456"
new BigInt(123); // should error
>new BigInt(123) : any
>BigInt : BigIntConstructor
>123 : 123
bigintVal = BigInt.asIntN(8, 0xFFFFn);
>bigintVal = BigInt.asIntN(8, 0xFFFFn) : bigint
>bigintVal : bigint
>BigInt.asIntN(8, 0xFFFFn) : bigint
>BigInt.asIntN : (bits: number, int: bigint) => bigint
>BigInt : BigIntConstructor
>asIntN : (bits: number, int: bigint) => bigint
>8 : 8
>0xFFFFn : 65535n
bigintVal = BigInt.asUintN(8, 0xFFFFn);
>bigintVal = BigInt.asUintN(8, 0xFFFFn) : bigint
>bigintVal : bigint
>BigInt.asUintN(8, 0xFFFFn) : bigint
>BigInt.asUintN : (bits: number, int: bigint) => bigint
>BigInt : BigIntConstructor
>asUintN : (bits: number, int: bigint) => bigint
>8 : 8
>0xFFFFn : 65535n
bigintVal = bigintVal.valueOf();
>bigintVal = bigintVal.valueOf() : bigint
>bigintVal : bigint
>bigintVal.valueOf() : bigint
>bigintVal.valueOf : () => bigint
>bigintVal : bigint
>valueOf : () => bigint
let stringVal: string = bigintVal.toString();
>stringVal : string
>bigintVal.toString() : string
>bigintVal.toString : (radix?: number) => string
>bigintVal : bigint
>toString : (radix?: number) => string
stringVal = bigintVal.toString(2);
>stringVal = bigintVal.toString(2) : string
>stringVal : string
>bigintVal.toString(2) : string
>bigintVal.toString : (radix?: number) => string
>bigintVal : bigint
>toString : (radix?: number) => string
>2 : 2
stringVal = bigintVal.toLocaleString();
>stringVal = bigintVal.toLocaleString() : string
>stringVal : string
>bigintVal.toLocaleString() : string
>bigintVal.toLocaleString : () => string
>bigintVal : bigint
>toLocaleString : () => string
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
>bigIntArray : BigInt64Array
>new BigInt64Array() : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
bigIntArray = new BigInt64Array(10);
>bigIntArray = new BigInt64Array(10) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array(10) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>10 : 10
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
>bigIntArray = new BigInt64Array([1n, 2n, 3n]) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array([1n, 2n, 3n]) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>[1n, 2n, 3n] : bigint[]
>1n : 1n
>2n : 2n
>3n : 3n
bigIntArray = new BigInt64Array([1, 2, 3]); // should error
>bigIntArray = new BigInt64Array([1, 2, 3]) : any
>bigIntArray : BigInt64Array
>new BigInt64Array([1, 2, 3]) : any
>BigInt64Array : BigInt64ArrayConstructor
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
>bigIntArray = new BigInt64Array(new ArrayBuffer(80)) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array(new ArrayBuffer(80)) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
>bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array(new ArrayBuffer(80), 8) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
>bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array(new ArrayBuffer(80), 8, 3) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
>3 : 3
let len: number = bigIntArray.length;
>len : number
>bigIntArray.length : number
>bigIntArray : BigInt64Array
>length : number
bigIntArray.length = 10; // should error
>bigIntArray.length = 10 : 10
>bigIntArray.length : any
>bigIntArray : BigInt64Array
>length : any
>10 : 10
let arrayBufferLike: ArrayBufferView = bigIntArray;
>arrayBufferLike : ArrayBufferView
>bigIntArray : BigInt64Array
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
>bigUintArray : BigUint64Array
>new BigUint64Array() : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
bigUintArray = new BigUint64Array(10);
>bigUintArray = new BigUint64Array(10) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array(10) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>10 : 10
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
>bigUintArray = new BigUint64Array([1n, 2n, 3n]) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array([1n, 2n, 3n]) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>[1n, 2n, 3n] : bigint[]
>1n : 1n
>2n : 2n
>3n : 3n
bigUintArray = new BigUint64Array([1, 2, 3]); // should error
>bigUintArray = new BigUint64Array([1, 2, 3]) : any
>bigUintArray : BigUint64Array
>new BigUint64Array([1, 2, 3]) : any
>BigUint64Array : BigUint64ArrayConstructor
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
>bigUintArray = new BigUint64Array(new ArrayBuffer(80)) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array(new ArrayBuffer(80)) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
>bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array(new ArrayBuffer(80), 8) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
>bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array(new ArrayBuffer(80), 8, 3) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
>3 : 3
len = bigIntArray.length;
>len = bigIntArray.length : number
>len : number
>bigIntArray.length : number
>bigIntArray : BigInt64Array
>length : number
bigIntArray.length = 10; // should error
>bigIntArray.length = 10 : 10
>bigIntArray.length : any
>bigIntArray : BigInt64Array
>length : any
>10 : 10
arrayBufferLike = bigIntArray;
>arrayBufferLike = bigIntArray : BigInt64Array
>arrayBufferLike : ArrayBufferView
>bigIntArray : BigInt64Array
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
>dataView : DataView
>new DataView(new ArrayBuffer(80)) : DataView
>DataView : DataViewConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
dataView.setBigInt64(1, -1n);
>dataView.setBigInt64(1, -1n) : void
>dataView.setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>1 : 1
>-1n : -1n
>1n : 1n
dataView.setBigInt64(1, -1n, true);
>dataView.setBigInt64(1, -1n, true) : void
>dataView.setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>1 : 1
>-1n : -1n
>1n : 1n
>true : true
dataView.setBigInt64(1, -1); // should error
>dataView.setBigInt64(1, -1) : void
>dataView.setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>1 : 1
>-1 : -1
>1 : 1
dataView.setBigUint64(2, 123n);
>dataView.setBigUint64(2, 123n) : void
>dataView.setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>2 : 2
>123n : 123n
dataView.setBigUint64(2, 123n, true);
>dataView.setBigUint64(2, 123n, true) : void
>dataView.setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>2 : 2
>123n : 123n
>true : true
dataView.setBigUint64(2, 123); // should error
>dataView.setBigUint64(2, 123) : void
>dataView.setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>2 : 2
>123 : 123
bigintVal = dataView.getBigInt64(1);
>bigintVal = dataView.getBigInt64(1) : bigint
>bigintVal : bigint
>dataView.getBigInt64(1) : bigint
>dataView.getBigInt64 : (byteOffset: number, littleEndian?: boolean) => bigint
>dataView : DataView
>getBigInt64 : (byteOffset: number, littleEndian?: boolean) => bigint
>1 : 1
bigintVal = dataView.getBigInt64(1, true);
>bigintVal = dataView.getBigInt64(1, true) : bigint
>bigintVal : bigint
>dataView.getBigInt64(1, true) : bigint
>dataView.getBigInt64 : (byteOffset: number, littleEndian?: boolean) => bigint
>dataView : DataView
>getBigInt64 : (byteOffset: number, littleEndian?: boolean) => bigint
>1 : 1
>true : true
bigintVal = dataView.getBigUint64(2);
>bigintVal = dataView.getBigUint64(2) : bigint
>bigintVal : bigint
>dataView.getBigUint64(2) : bigint
>dataView.getBigUint64 : (byteOffset: number, littleEndian?: boolean) => bigint
>dataView : DataView
>getBigUint64 : (byteOffset: number, littleEndian?: boolean) => bigint
>2 : 2
bigintVal = dataView.getBigUint64(2, true);
>bigintVal = dataView.getBigUint64(2, true) : bigint
>bigintVal : bigint
>dataView.getBigUint64(2, true) : bigint
>dataView.getBigUint64 : (byteOffset: number, littleEndian?: boolean) => bigint
>dataView : DataView
>getBigUint64 : (byteOffset: number, littleEndian?: boolean) => bigint
>2 : 2
>true : true

View File

@@ -0,0 +1,155 @@
tests/cases/compiler/bigintWithoutLib.ts(4,25): error TS2304: Cannot find name 'BigInt'.
tests/cases/compiler/bigintWithoutLib.ts(5,13): error TS2304: Cannot find name 'BigInt'.
tests/cases/compiler/bigintWithoutLib.ts(6,5): error TS2304: Cannot find name 'BigInt'.
tests/cases/compiler/bigintWithoutLib.ts(7,13): error TS2304: Cannot find name 'BigInt'.
tests/cases/compiler/bigintWithoutLib.ts(8,13): error TS2304: Cannot find name 'BigInt'.
tests/cases/compiler/bigintWithoutLib.ts(9,1): error TS2322: Type 'Object' is not assignable to type 'bigint'.
tests/cases/compiler/bigintWithoutLib.ts(11,13): error TS2554: Expected 0 arguments, but got 1.
tests/cases/compiler/bigintWithoutLib.ts(15,18): error TS2304: Cannot find name 'BigInt64Array'.
tests/cases/compiler/bigintWithoutLib.ts(15,38): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
tests/cases/compiler/bigintWithoutLib.ts(16,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
tests/cases/compiler/bigintWithoutLib.ts(17,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
tests/cases/compiler/bigintWithoutLib.ts(18,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
tests/cases/compiler/bigintWithoutLib.ts(19,19): error TS2304: Cannot find name 'BigInt64Array'.
tests/cases/compiler/bigintWithoutLib.ts(20,19): error TS2304: Cannot find name 'BigInt64Array'.
tests/cases/compiler/bigintWithoutLib.ts(21,19): error TS2304: Cannot find name 'BigInt64Array'.
tests/cases/compiler/bigintWithoutLib.ts(27,19): error TS2304: Cannot find name 'BigUint64Array'.
tests/cases/compiler/bigintWithoutLib.ts(27,40): error TS2304: Cannot find name 'BigUint64Array'.
tests/cases/compiler/bigintWithoutLib.ts(28,20): error TS2304: Cannot find name 'BigUint64Array'.
tests/cases/compiler/bigintWithoutLib.ts(29,20): error TS2304: Cannot find name 'BigUint64Array'.
tests/cases/compiler/bigintWithoutLib.ts(30,20): error TS2304: Cannot find name 'BigUint64Array'.
tests/cases/compiler/bigintWithoutLib.ts(31,20): error TS2304: Cannot find name 'BigUint64Array'.
tests/cases/compiler/bigintWithoutLib.ts(32,20): error TS2304: Cannot find name 'BigUint64Array'.
tests/cases/compiler/bigintWithoutLib.ts(33,20): error TS2304: Cannot find name 'BigUint64Array'.
tests/cases/compiler/bigintWithoutLib.ts(40,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'.
tests/cases/compiler/bigintWithoutLib.ts(41,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'.
tests/cases/compiler/bigintWithoutLib.ts(42,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'.
tests/cases/compiler/bigintWithoutLib.ts(43,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'.
tests/cases/compiler/bigintWithoutLib.ts(44,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'.
tests/cases/compiler/bigintWithoutLib.ts(45,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'.
tests/cases/compiler/bigintWithoutLib.ts(46,22): error TS2339: Property 'getBigInt64' does not exist on type 'DataView'.
tests/cases/compiler/bigintWithoutLib.ts(47,22): error TS2339: Property 'getBigInt64' does not exist on type 'DataView'.
tests/cases/compiler/bigintWithoutLib.ts(48,22): error TS2339: Property 'getBigUint64' does not exist on type 'DataView'.
tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigUint64' does not exist on type 'DataView'.
==== tests/cases/compiler/bigintWithoutLib.ts (33 errors) ====
// Every line should error because these builtins are not declared
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
~~~~~~
!!! error TS2304: Cannot find name 'BigInt'.
bigintVal = BigInt("456");
~~~~~~
!!! error TS2304: Cannot find name 'BigInt'.
new BigInt(123);
~~~~~~
!!! error TS2304: Cannot find name 'BigInt'.
bigintVal = BigInt.asIntN(8, 0xFFFFn);
~~~~~~
!!! error TS2304: Cannot find name 'BigInt'.
bigintVal = BigInt.asUintN(8, 0xFFFFn);
~~~~~~
!!! error TS2304: Cannot find name 'BigInt'.
bigintVal = bigintVal.valueOf(); // should error - bigintVal inferred as {}
~~~~~~~~~
!!! error TS2322: Type 'Object' is not assignable to type 'bigint'.
let stringVal: string = bigintVal.toString(); // should not error - bigintVal inferred as {}
stringVal = bigintVal.toString(2); // should error - bigintVal inferred as {}
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2554: Expected 0 arguments, but got 1.
stringVal = bigintVal.toLocaleString(); // should not error - bigintVal inferred as {}
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigInt64Array'.
~~~~~~~~~~~~~
!!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
!!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:15:5: 'bigIntArray' is declared here.
bigIntArray = new BigInt64Array(10);
~~~~~~~~~~~~~
!!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
!!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:15:5: 'bigIntArray' is declared here.
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
~~~~~~~~~~~~~
!!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
!!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:15:5: 'bigIntArray' is declared here.
bigIntArray = new BigInt64Array([1, 2, 3]);
~~~~~~~~~~~~~
!!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
!!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:15:5: 'bigIntArray' is declared here.
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigInt64Array'.
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigInt64Array'.
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigInt64Array'.
let len: number = bigIntArray.length;
bigIntArray.length = 10;
let arrayBufferLike: ArrayBufferView = bigIntArray;
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigUint64Array'.
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigUint64Array'.
bigUintArray = new BigUint64Array(10);
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigUint64Array'.
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigUint64Array'.
bigUintArray = new BigUint64Array([1, 2, 3]);
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigUint64Array'.
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigUint64Array'.
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigUint64Array'.
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'BigUint64Array'.
len = bigIntArray.length;
bigIntArray.length = 10;
arrayBufferLike = bigIntArray;
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
dataView.setBigInt64(1, -1n);
~~~~~~~~~~~
!!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'.
dataView.setBigInt64(1, -1n, true);
~~~~~~~~~~~
!!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'.
dataView.setBigInt64(1, -1);
~~~~~~~~~~~
!!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'.
dataView.setBigUint64(2, 123n);
~~~~~~~~~~~~
!!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'.
dataView.setBigUint64(2, 123n, true);
~~~~~~~~~~~~
!!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'.
dataView.setBigUint64(2, 123);
~~~~~~~~~~~~
!!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'.
bigintVal = dataView.getBigInt64(1);
~~~~~~~~~~~
!!! error TS2339: Property 'getBigInt64' does not exist on type 'DataView'.
bigintVal = dataView.getBigInt64(1, true);
~~~~~~~~~~~
!!! error TS2339: Property 'getBigInt64' does not exist on type 'DataView'.
bigintVal = dataView.getBigUint64(2);
~~~~~~~~~~~~
!!! error TS2339: Property 'getBigUint64' does not exist on type 'DataView'.
bigintVal = dataView.getBigUint64(2, true);
~~~~~~~~~~~~
!!! error TS2339: Property 'getBigUint64' does not exist on type 'DataView'.

View File

@@ -0,0 +1,97 @@
//// [bigintWithoutLib.ts]
// Every line should error because these builtins are not declared
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
bigintVal = BigInt("456");
new BigInt(123);
bigintVal = BigInt.asIntN(8, 0xFFFFn);
bigintVal = BigInt.asUintN(8, 0xFFFFn);
bigintVal = bigintVal.valueOf(); // should error - bigintVal inferred as {}
let stringVal: string = bigintVal.toString(); // should not error - bigintVal inferred as {}
stringVal = bigintVal.toString(2); // should error - bigintVal inferred as {}
stringVal = bigintVal.toLocaleString(); // should not error - bigintVal inferred as {}
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
bigIntArray = new BigInt64Array(10);
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
bigIntArray = new BigInt64Array([1, 2, 3]);
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
let len: number = bigIntArray.length;
bigIntArray.length = 10;
let arrayBufferLike: ArrayBufferView = bigIntArray;
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
bigUintArray = new BigUint64Array(10);
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
bigUintArray = new BigUint64Array([1, 2, 3]);
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
len = bigIntArray.length;
bigIntArray.length = 10;
arrayBufferLike = bigIntArray;
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
dataView.setBigInt64(1, -1n);
dataView.setBigInt64(1, -1n, true);
dataView.setBigInt64(1, -1);
dataView.setBigUint64(2, 123n);
dataView.setBigUint64(2, 123n, true);
dataView.setBigUint64(2, 123);
bigintVal = dataView.getBigInt64(1);
bigintVal = dataView.getBigInt64(1, true);
bigintVal = dataView.getBigUint64(2);
bigintVal = dataView.getBigUint64(2, true);
//// [bigintWithoutLib.js]
// Every line should error because these builtins are not declared
// Test BigInt functions
var bigintVal = BigInt(123);
bigintVal = BigInt("456");
new BigInt(123);
bigintVal = BigInt.asIntN(8, 0xFFFFn);
bigintVal = BigInt.asUintN(8, 0xFFFFn);
bigintVal = bigintVal.valueOf(); // should error - bigintVal inferred as {}
var stringVal = bigintVal.toString(); // should not error - bigintVal inferred as {}
stringVal = bigintVal.toString(2); // should error - bigintVal inferred as {}
stringVal = bigintVal.toLocaleString(); // should not error - bigintVal inferred as {}
// Test BigInt64Array
var bigIntArray = new BigInt64Array();
bigIntArray = new BigInt64Array(10);
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
bigIntArray = new BigInt64Array([1, 2, 3]);
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
var len = bigIntArray.length;
bigIntArray.length = 10;
var arrayBufferLike = bigIntArray;
// Test BigUint64Array
var bigUintArray = new BigUint64Array();
bigUintArray = new BigUint64Array(10);
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
bigUintArray = new BigUint64Array([1, 2, 3]);
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
len = bigIntArray.length;
bigIntArray.length = 10;
arrayBufferLike = bigIntArray;
// Test added DataView methods
var dataView = new DataView(new ArrayBuffer(80));
dataView.setBigInt64(1, -1n);
dataView.setBigInt64(1, -1n, true);
dataView.setBigInt64(1, -1);
dataView.setBigUint64(2, 123n);
dataView.setBigUint64(2, 123n, true);
dataView.setBigUint64(2, 123);
bigintVal = dataView.getBigInt64(1);
bigintVal = dataView.getBigInt64(1, true);
bigintVal = dataView.getBigUint64(2);
bigintVal = dataView.getBigUint64(2, true);

View File

@@ -0,0 +1,154 @@
=== tests/cases/compiler/bigintWithoutLib.ts ===
// Every line should error because these builtins are not declared
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
bigintVal = BigInt("456");
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
new BigInt(123);
bigintVal = BigInt.asIntN(8, 0xFFFFn);
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
bigintVal = BigInt.asUintN(8, 0xFFFFn);
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
bigintVal = bigintVal.valueOf(); // should error - bigintVal inferred as {}
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
>bigintVal.valueOf : Symbol(Object.valueOf, Decl(lib.es5.d.ts, --, --))
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
>valueOf : Symbol(Object.valueOf, Decl(lib.es5.d.ts, --, --))
let stringVal: string = bigintVal.toString(); // should not error - bigintVal inferred as {}
>stringVal : Symbol(stringVal, Decl(bigintWithoutLib.ts, 9, 3))
>bigintVal.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
stringVal = bigintVal.toString(2); // should error - bigintVal inferred as {}
>stringVal : Symbol(stringVal, Decl(bigintWithoutLib.ts, 9, 3))
>bigintVal.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
stringVal = bigintVal.toLocaleString(); // should not error - bigintVal inferred as {}
>stringVal : Symbol(stringVal, Decl(bigintWithoutLib.ts, 9, 3))
>bigintVal.toLocaleString : Symbol(Object.toLocaleString, Decl(lib.es5.d.ts, --, --))
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
>toLocaleString : Symbol(Object.toLocaleString, Decl(lib.es5.d.ts, --, --))
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
bigIntArray = new BigInt64Array(10);
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
bigIntArray = new BigInt64Array([1, 2, 3]);
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
let len: number = bigIntArray.length;
>len : Symbol(len, Decl(bigintWithoutLib.ts, 21, 3))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
bigIntArray.length = 10;
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
let arrayBufferLike: ArrayBufferView = bigIntArray;
>arrayBufferLike : Symbol(arrayBufferLike, Decl(bigintWithoutLib.ts, 23, 3))
>ArrayBufferView : Symbol(ArrayBufferView, Decl(lib.es5.d.ts, --, --))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithoutLib.ts, 26, 3))
bigUintArray = new BigUint64Array(10);
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithoutLib.ts, 26, 3))
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithoutLib.ts, 26, 3))
bigUintArray = new BigUint64Array([1, 2, 3]);
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithoutLib.ts, 26, 3))
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithoutLib.ts, 26, 3))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithoutLib.ts, 26, 3))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
>bigUintArray : Symbol(bigUintArray, Decl(bigintWithoutLib.ts, 26, 3))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
len = bigIntArray.length;
>len : Symbol(len, Decl(bigintWithoutLib.ts, 21, 3))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
bigIntArray.length = 10;
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
arrayBufferLike = bigIntArray;
>arrayBufferLike : Symbol(arrayBufferLike, Decl(bigintWithoutLib.ts, 23, 3))
>bigIntArray : Symbol(bigIntArray, Decl(bigintWithoutLib.ts, 14, 3))
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
>DataView : Symbol(DataView, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
dataView.setBigInt64(1, -1n);
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
dataView.setBigInt64(1, -1n, true);
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
dataView.setBigInt64(1, -1);
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
dataView.setBigUint64(2, 123n);
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
dataView.setBigUint64(2, 123n, true);
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
dataView.setBigUint64(2, 123);
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
bigintVal = dataView.getBigInt64(1);
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
bigintVal = dataView.getBigInt64(1, true);
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
bigintVal = dataView.getBigUint64(2);
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))
bigintVal = dataView.getBigUint64(2, true);
>bigintVal : Symbol(bigintVal, Decl(bigintWithoutLib.ts, 3, 3))
>dataView : Symbol(dataView, Decl(bigintWithoutLib.ts, 38, 5))

View File

@@ -0,0 +1,336 @@
=== tests/cases/compiler/bigintWithoutLib.ts ===
// Every line should error because these builtins are not declared
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
>bigintVal : bigint
>BigInt(123) : any
>BigInt : any
>123 : 123
bigintVal = BigInt("456");
>bigintVal = BigInt("456") : any
>bigintVal : bigint
>BigInt("456") : any
>BigInt : any
>"456" : "456"
new BigInt(123);
>new BigInt(123) : any
>BigInt : any
>123 : 123
bigintVal = BigInt.asIntN(8, 0xFFFFn);
>bigintVal = BigInt.asIntN(8, 0xFFFFn) : any
>bigintVal : bigint
>BigInt.asIntN(8, 0xFFFFn) : any
>BigInt.asIntN : any
>BigInt : any
>asIntN : any
>8 : 8
>0xFFFFn : 65535n
bigintVal = BigInt.asUintN(8, 0xFFFFn);
>bigintVal = BigInt.asUintN(8, 0xFFFFn) : any
>bigintVal : bigint
>BigInt.asUintN(8, 0xFFFFn) : any
>BigInt.asUintN : any
>BigInt : any
>asUintN : any
>8 : 8
>0xFFFFn : 65535n
bigintVal = bigintVal.valueOf(); // should error - bigintVal inferred as {}
>bigintVal = bigintVal.valueOf() : Object
>bigintVal : bigint
>bigintVal.valueOf() : Object
>bigintVal.valueOf : () => Object
>bigintVal : bigint
>valueOf : () => Object
let stringVal: string = bigintVal.toString(); // should not error - bigintVal inferred as {}
>stringVal : string
>bigintVal.toString() : string
>bigintVal.toString : () => string
>bigintVal : bigint
>toString : () => string
stringVal = bigintVal.toString(2); // should error - bigintVal inferred as {}
>stringVal = bigintVal.toString(2) : any
>stringVal : string
>bigintVal.toString(2) : string
>bigintVal.toString : () => string
>bigintVal : bigint
>toString : () => string
>2 : 2
stringVal = bigintVal.toLocaleString(); // should not error - bigintVal inferred as {}
>stringVal = bigintVal.toLocaleString() : string
>stringVal : string
>bigintVal.toLocaleString() : string
>bigintVal.toLocaleString : () => string
>bigintVal : bigint
>toLocaleString : () => string
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
>bigIntArray : any
>new BigInt64Array() : any
>BigInt64Array : any
bigIntArray = new BigInt64Array(10);
>bigIntArray = new BigInt64Array(10) : any
>bigIntArray : any
>new BigInt64Array(10) : any
>BigInt64Array : any
>10 : 10
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
>bigIntArray = new BigInt64Array([1n, 2n, 3n]) : any
>bigIntArray : any
>new BigInt64Array([1n, 2n, 3n]) : any
>BigInt64Array : any
>[1n, 2n, 3n] : bigint[]
>1n : 1n
>2n : 2n
>3n : 3n
bigIntArray = new BigInt64Array([1, 2, 3]);
>bigIntArray = new BigInt64Array([1, 2, 3]) : any
>bigIntArray : any
>new BigInt64Array([1, 2, 3]) : any
>BigInt64Array : any
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
>bigIntArray = new BigInt64Array(new ArrayBuffer(80)) : any
>bigIntArray : any
>new BigInt64Array(new ArrayBuffer(80)) : any
>BigInt64Array : any
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
>bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8) : any
>bigIntArray : any
>new BigInt64Array(new ArrayBuffer(80), 8) : any
>BigInt64Array : any
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
>bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3) : any
>bigIntArray : any
>new BigInt64Array(new ArrayBuffer(80), 8, 3) : any
>BigInt64Array : any
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
>3 : 3
let len: number = bigIntArray.length;
>len : number
>bigIntArray.length : any
>bigIntArray : any
>length : any
bigIntArray.length = 10;
>bigIntArray.length = 10 : 10
>bigIntArray.length : any
>bigIntArray : any
>length : any
>10 : 10
let arrayBufferLike: ArrayBufferView = bigIntArray;
>arrayBufferLike : ArrayBufferView
>bigIntArray : any
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
>bigUintArray : any
>new BigUint64Array() : any
>BigUint64Array : any
bigUintArray = new BigUint64Array(10);
>bigUintArray = new BigUint64Array(10) : any
>bigUintArray : any
>new BigUint64Array(10) : any
>BigUint64Array : any
>10 : 10
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
>bigUintArray = new BigUint64Array([1n, 2n, 3n]) : any
>bigUintArray : any
>new BigUint64Array([1n, 2n, 3n]) : any
>BigUint64Array : any
>[1n, 2n, 3n] : bigint[]
>1n : 1n
>2n : 2n
>3n : 3n
bigUintArray = new BigUint64Array([1, 2, 3]);
>bigUintArray = new BigUint64Array([1, 2, 3]) : any
>bigUintArray : any
>new BigUint64Array([1, 2, 3]) : any
>BigUint64Array : any
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
>bigUintArray = new BigUint64Array(new ArrayBuffer(80)) : any
>bigUintArray : any
>new BigUint64Array(new ArrayBuffer(80)) : any
>BigUint64Array : any
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
>bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8) : any
>bigUintArray : any
>new BigUint64Array(new ArrayBuffer(80), 8) : any
>BigUint64Array : any
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
>bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3) : any
>bigUintArray : any
>new BigUint64Array(new ArrayBuffer(80), 8, 3) : any
>BigUint64Array : any
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
>3 : 3
len = bigIntArray.length;
>len = bigIntArray.length : any
>len : number
>bigIntArray.length : any
>bigIntArray : any
>length : any
bigIntArray.length = 10;
>bigIntArray.length = 10 : 10
>bigIntArray.length : any
>bigIntArray : any
>length : any
>10 : 10
arrayBufferLike = bigIntArray;
>arrayBufferLike = bigIntArray : any
>arrayBufferLike : ArrayBufferView
>bigIntArray : any
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
>dataView : DataView
>new DataView(new ArrayBuffer(80)) : DataView
>DataView : DataViewConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
dataView.setBigInt64(1, -1n);
>dataView.setBigInt64(1, -1n) : any
>dataView.setBigInt64 : any
>dataView : DataView
>setBigInt64 : any
>1 : 1
>-1n : -1n
>1n : 1n
dataView.setBigInt64(1, -1n, true);
>dataView.setBigInt64(1, -1n, true) : any
>dataView.setBigInt64 : any
>dataView : DataView
>setBigInt64 : any
>1 : 1
>-1n : -1n
>1n : 1n
>true : true
dataView.setBigInt64(1, -1);
>dataView.setBigInt64(1, -1) : any
>dataView.setBigInt64 : any
>dataView : DataView
>setBigInt64 : any
>1 : 1
>-1 : -1
>1 : 1
dataView.setBigUint64(2, 123n);
>dataView.setBigUint64(2, 123n) : any
>dataView.setBigUint64 : any
>dataView : DataView
>setBigUint64 : any
>2 : 2
>123n : 123n
dataView.setBigUint64(2, 123n, true);
>dataView.setBigUint64(2, 123n, true) : any
>dataView.setBigUint64 : any
>dataView : DataView
>setBigUint64 : any
>2 : 2
>123n : 123n
>true : true
dataView.setBigUint64(2, 123);
>dataView.setBigUint64(2, 123) : any
>dataView.setBigUint64 : any
>dataView : DataView
>setBigUint64 : any
>2 : 2
>123 : 123
bigintVal = dataView.getBigInt64(1);
>bigintVal = dataView.getBigInt64(1) : any
>bigintVal : bigint
>dataView.getBigInt64(1) : any
>dataView.getBigInt64 : any
>dataView : DataView
>getBigInt64 : any
>1 : 1
bigintVal = dataView.getBigInt64(1, true);
>bigintVal = dataView.getBigInt64(1, true) : any
>bigintVal : bigint
>dataView.getBigInt64(1, true) : any
>dataView.getBigInt64 : any
>dataView : DataView
>getBigInt64 : any
>1 : 1
>true : true
bigintVal = dataView.getBigUint64(2);
>bigintVal = dataView.getBigUint64(2) : any
>bigintVal : bigint
>dataView.getBigUint64(2) : any
>dataView.getBigUint64 : any
>dataView : DataView
>getBigUint64 : any
>2 : 2
bigintVal = dataView.getBigUint64(2, true);
>bigintVal = dataView.getBigUint64(2, true) : any
>bigintVal : bigint
>dataView.getBigUint64(2, true) : any
>dataView.getBigUint64 : any
>dataView : DataView
>getBigUint64 : any
>2 : 2
>true : true

View File

@@ -0,0 +1,289 @@
tests/cases/compiler/numberVsBigIntOperations.ts(3,14): error TS2322: Type '2' is not assignable to type 'bigint'.
tests/cases/compiler/numberVsBigIntOperations.ts(3,26): error TS2322: Type '1n' is not assignable to type 'number'.
tests/cases/compiler/numberVsBigIntOperations.ts(4,15): error TS2365: Operator '+=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(4,28): error TS2365: Operator '+=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(5,15): error TS2365: Operator '-=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(5,28): error TS2365: Operator '-=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(6,15): error TS2365: Operator '*=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(6,28): error TS2365: Operator '*=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(7,15): error TS2365: Operator '/=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(7,28): error TS2365: Operator '/=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(8,15): error TS2365: Operator '%=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(8,28): error TS2365: Operator '%=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(9,16): error TS2365: Operator '**=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(9,30): error TS2365: Operator '**=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(10,16): error TS2365: Operator '<<=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(10,30): error TS2365: Operator '<<=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(11,16): error TS2365: Operator '>>=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(11,30): error TS2365: Operator '>>=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(12,15): error TS2365: Operator '&=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(12,28): error TS2365: Operator '&=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(13,15): error TS2365: Operator '^=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(13,28): error TS2365: Operator '^=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(14,15): error TS2365: Operator '|=' cannot be applied to types 'bigint' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(14,28): error TS2365: Operator '|=' cannot be applied to types 'number' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(15,32): error TS2365: Operator '+' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(15,40): error TS2365: Operator '+' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(16,32): error TS2365: Operator '-' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(16,40): error TS2365: Operator '-' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(17,32): error TS2365: Operator '*' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(17,40): error TS2365: Operator '*' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(18,32): error TS2365: Operator '/' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(18,40): error TS2365: Operator '/' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(19,32): error TS2365: Operator '%' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(19,40): error TS2365: Operator '%' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(20,34): error TS2365: Operator '**' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(20,43): error TS2365: Operator '**' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(21,32): error TS2365: Operator '&' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(21,40): error TS2365: Operator '&' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(22,32): error TS2365: Operator '|' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(22,40): error TS2365: Operator '|' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(23,32): error TS2365: Operator '^' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(23,40): error TS2365: Operator '^' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(24,34): error TS2365: Operator '<<' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(24,43): error TS2365: Operator '<<' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(25,34): error TS2365: Operator '>>' cannot be applied to types '1' and '2n'.
tests/cases/compiler/numberVsBigIntOperations.ts(25,43): error TS2365: Operator '>>' cannot be applied to types '1n' and '2'.
tests/cases/compiler/numberVsBigIntOperations.ts(38,1): error TS2365: Operator '>>>=' cannot be applied to types 'bigint' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(39,10): error TS2365: Operator '>>>' cannot be applied to types 'bigint' and '1n'.
tests/cases/compiler/numberVsBigIntOperations.ts(40,8): error TS2735: Operator '+' cannot be applied to type 'bigint'.
tests/cases/compiler/numberVsBigIntOperations.ts(50,10): error TS2367: This condition will always return 'false' since the types 'bigint' and 'number' have no overlap.
tests/cases/compiler/numberVsBigIntOperations.ts(51,10): error TS2367: This condition will always return 'true' since the types 'bigint' and 'number' have no overlap.
tests/cases/compiler/numberVsBigIntOperations.ts(52,10): error TS2367: This condition will always return 'false' since the types 'bigint' and 'number' have no overlap.
tests/cases/compiler/numberVsBigIntOperations.ts(53,10): error TS2367: This condition will always return 'true' since the types 'bigint' and 'number' have no overlap.
tests/cases/compiler/numberVsBigIntOperations.ts(56,7): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
tests/cases/compiler/numberVsBigIntOperations.ts(56,27): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
tests/cases/compiler/numberVsBigIntOperations.ts(57,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
tests/cases/compiler/numberVsBigIntOperations.ts(57,1): error TS2365: Operator '&' cannot be applied to types '"3"' and '5n'.
tests/cases/compiler/numberVsBigIntOperations.ts(57,11): error TS2365: Operator '**' cannot be applied to types '2n' and 'false'.
tests/cases/compiler/numberVsBigIntOperations.ts(57,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
tests/cases/compiler/numberVsBigIntOperations.ts(60,1): error TS2365: Operator '+' cannot be applied to types 'number | bigint' and 'number | bigint'.
tests/cases/compiler/numberVsBigIntOperations.ts(61,1): error TS2365: Operator '<<' cannot be applied to types 'number | bigint' and 'number | bigint'.
tests/cases/compiler/numberVsBigIntOperations.ts(70,2): error TS2735: Operator '+' cannot be applied to type 'number | bigint'.
tests/cases/compiler/numberVsBigIntOperations.ts(86,7): error TS1155: 'const' declarations must be initialized.
tests/cases/compiler/numberVsBigIntOperations.ts(93,7): error TS1155: 'const' declarations must be initialized.
==== tests/cases/compiler/numberVsBigIntOperations.ts (64 errors) ====
// Cannot mix bigints and numbers
let bigInt = 1n, num = 2;
bigInt = 1n; bigInt = 2; num = 1n; num = 2;
~~~~~~
!!! error TS2322: Type '2' is not assignable to type 'bigint'.
~~~
!!! error TS2322: Type '1n' is not assignable to type 'number'.
bigInt += 1n; bigInt += 2; num += 1n; num += 2;
~~~~~~~~~~~
!!! error TS2365: Operator '+=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~
!!! error TS2365: Operator '+=' cannot be applied to types 'number' and '1n'.
bigInt -= 1n; bigInt -= 2; num -= 1n; num -= 2;
~~~~~~~~~~~
!!! error TS2365: Operator '-=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~
!!! error TS2365: Operator '-=' cannot be applied to types 'number' and '1n'.
bigInt *= 1n; bigInt *= 2; num *= 1n; num *= 2;
~~~~~~~~~~~
!!! error TS2365: Operator '*=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~
!!! error TS2365: Operator '*=' cannot be applied to types 'number' and '1n'.
bigInt /= 1n; bigInt /= 2; num /= 1n; num /= 2;
~~~~~~~~~~~
!!! error TS2365: Operator '/=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~
!!! error TS2365: Operator '/=' cannot be applied to types 'number' and '1n'.
bigInt %= 1n; bigInt %= 2; num %= 1n; num %= 2;
~~~~~~~~~~~
!!! error TS2365: Operator '%=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~
!!! error TS2365: Operator '%=' cannot be applied to types 'number' and '1n'.
bigInt **= 1n; bigInt **= 2; num **= 1n; num **= 2;
~~~~~~~~~~~~
!!! error TS2365: Operator '**=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~~
!!! error TS2365: Operator '**=' cannot be applied to types 'number' and '1n'.
bigInt <<= 1n; bigInt <<= 2; num <<= 1n; num <<= 2;
~~~~~~~~~~~~
!!! error TS2365: Operator '<<=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~~
!!! error TS2365: Operator '<<=' cannot be applied to types 'number' and '1n'.
bigInt >>= 1n; bigInt >>= 2; num >>= 1n; num >>= 2;
~~~~~~~~~~~~
!!! error TS2365: Operator '>>=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~~
!!! error TS2365: Operator '>>=' cannot be applied to types 'number' and '1n'.
bigInt &= 1n; bigInt &= 2; num &= 1n; num &= 2;
~~~~~~~~~~~
!!! error TS2365: Operator '&=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~
!!! error TS2365: Operator '&=' cannot be applied to types 'number' and '1n'.
bigInt ^= 1n; bigInt ^= 2; num ^= 1n; num ^= 2;
~~~~~~~~~~~
!!! error TS2365: Operator '^=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~
!!! error TS2365: Operator '^=' cannot be applied to types 'number' and '1n'.
bigInt |= 1n; bigInt |= 2; num |= 1n; num |= 2;
~~~~~~~~~~~
!!! error TS2365: Operator '|=' cannot be applied to types 'bigint' and '2'.
~~~~~~~~~
!!! error TS2365: Operator '|=' cannot be applied to types 'number' and '1n'.
bigInt = 1n + 2n; num = 1 + 2; 1 + 2n; 1n + 2;
~~~~~~
!!! error TS2365: Operator '+' cannot be applied to types '1' and '2n'.
~~~~~~
!!! error TS2365: Operator '+' cannot be applied to types '1n' and '2'.
bigInt = 1n - 2n; num = 1 - 2; 1 - 2n; 1n - 2;
~~~~~~
!!! error TS2365: Operator '-' cannot be applied to types '1' and '2n'.
~~~~~~
!!! error TS2365: Operator '-' cannot be applied to types '1n' and '2'.
bigInt = 1n * 2n; num = 1 * 2; 1 * 2n; 1n * 2;
~~~~~~
!!! error TS2365: Operator '*' cannot be applied to types '1' and '2n'.
~~~~~~
!!! error TS2365: Operator '*' cannot be applied to types '1n' and '2'.
bigInt = 1n / 2n; num = 1 / 2; 1 / 2n; 1n / 2;
~~~~~~
!!! error TS2365: Operator '/' cannot be applied to types '1' and '2n'.
~~~~~~
!!! error TS2365: Operator '/' cannot be applied to types '1n' and '2'.
bigInt = 1n % 2n; num = 1 % 2; 1 % 2n; 1n % 2;
~~~~~~
!!! error TS2365: Operator '%' cannot be applied to types '1' and '2n'.
~~~~~~
!!! error TS2365: Operator '%' cannot be applied to types '1n' and '2'.
bigInt = 1n ** 2n; num = 1 ** 2; 1 ** 2n; 1n ** 2;
~~~~~~~
!!! error TS2365: Operator '**' cannot be applied to types '1' and '2n'.
~~~~~~~
!!! error TS2365: Operator '**' cannot be applied to types '1n' and '2'.
bigInt = 1n & 2n; num = 1 & 2; 1 & 2n; 1n & 2;
~~~~~~
!!! error TS2365: Operator '&' cannot be applied to types '1' and '2n'.
~~~~~~
!!! error TS2365: Operator '&' cannot be applied to types '1n' and '2'.
bigInt = 1n | 2n; num = 1 | 2; 1 | 2n; 1n | 2;
~~~~~~
!!! error TS2365: Operator '|' cannot be applied to types '1' and '2n'.
~~~~~~
!!! error TS2365: Operator '|' cannot be applied to types '1n' and '2'.
bigInt = 1n ^ 2n; num = 1 ^ 2; 1 ^ 2n; 1n ^ 2;
~~~~~~
!!! error TS2365: Operator '^' cannot be applied to types '1' and '2n'.
~~~~~~
!!! error TS2365: Operator '^' cannot be applied to types '1n' and '2'.
bigInt = 1n << 2n; num = 1 << 2; 1 << 2n; 1n << 2;
~~~~~~~
!!! error TS2365: Operator '<<' cannot be applied to types '1' and '2n'.
~~~~~~~
!!! error TS2365: Operator '<<' cannot be applied to types '1n' and '2'.
bigInt = 1n >> 2n; num = 1 >> 2; 1 >> 2n; 1n >> 2;
~~~~~~~
!!! error TS2365: Operator '>>' cannot be applied to types '1' and '2n'.
~~~~~~~
!!! error TS2365: Operator '>>' cannot be applied to types '1n' and '2'.
// Plus should still coerce to strings
let str: string;
str = "abc" + 123; str = "abc" + 123n; str = 123 + "abc"; str = 123n + "abc";
// Unary operations allowed on bigints and numbers
bigInt = bigInt++; bigInt = ++bigInt; num = num++; num = ++num;
bigInt = bigInt--; bigInt = --bigInt; num = num--; num = --num;
bigInt = -bigInt; num = -num;
bigInt = ~bigInt; num = ~num;
// Number-only operations
bigInt >>>= 1n; num >>>= 2;
~~~~~~~~~~~~~~
!!! error TS2365: Operator '>>>=' cannot be applied to types 'bigint' and '1n'.
bigInt = bigInt >>> 1n; num = num >>> 2;
~~~~~~~~~~~~~
!!! error TS2365: Operator '>>>' cannot be applied to types 'bigint' and '1n'.
num = +bigInt; num = +num; num = +"3";
~~~~~~
!!! error TS2735: Operator '+' cannot be applied to type 'bigint'.
// Comparisons can be mixed
let result: boolean;
result = bigInt > num;
result = bigInt >= num;
result = bigInt < num;
result = bigInt <= num;
// Trying to compare for equality is likely an error (since 1 == "1" is disallowed)
result = bigInt == num;
~~~~~~~~~~~~~
!!! error TS2367: This condition will always return 'false' since the types 'bigint' and 'number' have no overlap.
result = bigInt != num;
~~~~~~~~~~~~~
!!! error TS2367: This condition will always return 'true' since the types 'bigint' and 'number' have no overlap.
result = bigInt === num;
~~~~~~~~~~~~~~
!!! error TS2367: This condition will always return 'false' since the types 'bigint' and 'number' have no overlap.
result = bigInt !== num;
~~~~~~~~~~~~~~
!!! error TS2367: This condition will always return 'true' since the types 'bigint' and 'number' have no overlap.
// Types of arithmetic operations on other types
num = "3" & 5; num = 2 ** false; // should error, but infer number
~~~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
~~~~~
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
"3" & 5n; 2n ** false; // should error, result in any
~~~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
~~~~~~~~
!!! error TS2365: Operator '&' cannot be applied to types '"3"' and '5n'.
~~~~~~~~~~~
!!! error TS2365: Operator '**' cannot be applied to types '2n' and 'false'.
~~~~~
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
num = ~"3"; num = -false; // should infer number
let bigIntOrNumber: bigint | number;
bigIntOrNumber + bigIntOrNumber; // should error, result in any
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '+' cannot be applied to types 'number | bigint' and 'number | bigint'.
bigIntOrNumber << bigIntOrNumber; // should error, result in any
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '<<' cannot be applied to types 'number | bigint' and 'number | bigint'.
if (typeof bigIntOrNumber === "bigint") {
// Allowed, as type is narrowed to bigint
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
}
if (typeof bigIntOrNumber === "number") {
// Allowed, as type is narrowed to number
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
}
+bigIntOrNumber; // should error, result in number
~~~~~~~~~~~~~~
!!! error TS2735: Operator '+' cannot be applied to type 'number | bigint'.
~bigIntOrNumber; // should infer number | bigint
bigIntOrNumber++; // should infer number | bigint
++bigIntOrNumber; // should infer number | bigint
let anyValue: any;
anyValue + anyValue; // should infer any
anyValue >>> anyValue; // should infer number
anyValue ^ anyValue; // should infer number
+anyValue; // should infer number
-anyValue; // should infer number
anyValue--; // should infer number
--anyValue; // should infer number
// Distinguishing numbers from bigints with typeof
const isBigInt: (x: 0n | 1n) => bigint = (x: 0n | 1n) => x;
const isNumber: (x: 0 | 1) => number = (x: 0 | 1) => x;
const zeroOrBigOne: 0 | 1n;
~~~~~~~~~~~~
!!! error TS1155: 'const' declarations must be initialized.
if (typeof zeroOrBigOne === "bigint") isBigInt(zeroOrBigOne);
else isNumber(zeroOrBigOne);
// Distinguishing truthy from falsy
const isOne = (x: 1 | 1n) => x;
if (zeroOrBigOne) isOne(zeroOrBigOne);
const bigZeroOrOne: 0n | 1;
~~~~~~~~~~~~
!!! error TS1155: 'const' declarations must be initialized.
if (bigZeroOrOne) isOne(bigZeroOrOne);

View File

@@ -0,0 +1,274 @@
//// [numberVsBigIntOperations.ts]
// Cannot mix bigints and numbers
let bigInt = 1n, num = 2;
bigInt = 1n; bigInt = 2; num = 1n; num = 2;
bigInt += 1n; bigInt += 2; num += 1n; num += 2;
bigInt -= 1n; bigInt -= 2; num -= 1n; num -= 2;
bigInt *= 1n; bigInt *= 2; num *= 1n; num *= 2;
bigInt /= 1n; bigInt /= 2; num /= 1n; num /= 2;
bigInt %= 1n; bigInt %= 2; num %= 1n; num %= 2;
bigInt **= 1n; bigInt **= 2; num **= 1n; num **= 2;
bigInt <<= 1n; bigInt <<= 2; num <<= 1n; num <<= 2;
bigInt >>= 1n; bigInt >>= 2; num >>= 1n; num >>= 2;
bigInt &= 1n; bigInt &= 2; num &= 1n; num &= 2;
bigInt ^= 1n; bigInt ^= 2; num ^= 1n; num ^= 2;
bigInt |= 1n; bigInt |= 2; num |= 1n; num |= 2;
bigInt = 1n + 2n; num = 1 + 2; 1 + 2n; 1n + 2;
bigInt = 1n - 2n; num = 1 - 2; 1 - 2n; 1n - 2;
bigInt = 1n * 2n; num = 1 * 2; 1 * 2n; 1n * 2;
bigInt = 1n / 2n; num = 1 / 2; 1 / 2n; 1n / 2;
bigInt = 1n % 2n; num = 1 % 2; 1 % 2n; 1n % 2;
bigInt = 1n ** 2n; num = 1 ** 2; 1 ** 2n; 1n ** 2;
bigInt = 1n & 2n; num = 1 & 2; 1 & 2n; 1n & 2;
bigInt = 1n | 2n; num = 1 | 2; 1 | 2n; 1n | 2;
bigInt = 1n ^ 2n; num = 1 ^ 2; 1 ^ 2n; 1n ^ 2;
bigInt = 1n << 2n; num = 1 << 2; 1 << 2n; 1n << 2;
bigInt = 1n >> 2n; num = 1 >> 2; 1 >> 2n; 1n >> 2;
// Plus should still coerce to strings
let str: string;
str = "abc" + 123; str = "abc" + 123n; str = 123 + "abc"; str = 123n + "abc";
// Unary operations allowed on bigints and numbers
bigInt = bigInt++; bigInt = ++bigInt; num = num++; num = ++num;
bigInt = bigInt--; bigInt = --bigInt; num = num--; num = --num;
bigInt = -bigInt; num = -num;
bigInt = ~bigInt; num = ~num;
// Number-only operations
bigInt >>>= 1n; num >>>= 2;
bigInt = bigInt >>> 1n; num = num >>> 2;
num = +bigInt; num = +num; num = +"3";
// Comparisons can be mixed
let result: boolean;
result = bigInt > num;
result = bigInt >= num;
result = bigInt < num;
result = bigInt <= num;
// Trying to compare for equality is likely an error (since 1 == "1" is disallowed)
result = bigInt == num;
result = bigInt != num;
result = bigInt === num;
result = bigInt !== num;
// Types of arithmetic operations on other types
num = "3" & 5; num = 2 ** false; // should error, but infer number
"3" & 5n; 2n ** false; // should error, result in any
num = ~"3"; num = -false; // should infer number
let bigIntOrNumber: bigint | number;
bigIntOrNumber + bigIntOrNumber; // should error, result in any
bigIntOrNumber << bigIntOrNumber; // should error, result in any
if (typeof bigIntOrNumber === "bigint") {
// Allowed, as type is narrowed to bigint
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
}
if (typeof bigIntOrNumber === "number") {
// Allowed, as type is narrowed to number
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
}
+bigIntOrNumber; // should error, result in number
~bigIntOrNumber; // should infer number | bigint
bigIntOrNumber++; // should infer number | bigint
++bigIntOrNumber; // should infer number | bigint
let anyValue: any;
anyValue + anyValue; // should infer any
anyValue >>> anyValue; // should infer number
anyValue ^ anyValue; // should infer number
+anyValue; // should infer number
-anyValue; // should infer number
anyValue--; // should infer number
--anyValue; // should infer number
// Distinguishing numbers from bigints with typeof
const isBigInt: (x: 0n | 1n) => bigint = (x: 0n | 1n) => x;
const isNumber: (x: 0 | 1) => number = (x: 0 | 1) => x;
const zeroOrBigOne: 0 | 1n;
if (typeof zeroOrBigOne === "bigint") isBigInt(zeroOrBigOne);
else isNumber(zeroOrBigOne);
// Distinguishing truthy from falsy
const isOne = (x: 1 | 1n) => x;
if (zeroOrBigOne) isOne(zeroOrBigOne);
const bigZeroOrOne: 0n | 1;
if (bigZeroOrOne) isOne(bigZeroOrOne);
//// [numberVsBigIntOperations.js]
// Cannot mix bigints and numbers
var bigInt = 1n, num = 2;
bigInt = 1n;
bigInt = 2;
num = 1n;
num = 2;
bigInt += 1n;
bigInt += 2;
num += 1n;
num += 2;
bigInt -= 1n;
bigInt -= 2;
num -= 1n;
num -= 2;
bigInt *= 1n;
bigInt *= 2;
num *= 1n;
num *= 2;
bigInt /= 1n;
bigInt /= 2;
num /= 1n;
num /= 2;
bigInt %= 1n;
bigInt %= 2;
num %= 1n;
num %= 2;
bigInt = Math.pow(bigInt, 1n);
bigInt = Math.pow(bigInt, 2);
num = Math.pow(num, 1n);
num = Math.pow(num, 2);
bigInt <<= 1n;
bigInt <<= 2;
num <<= 1n;
num <<= 2;
bigInt >>= 1n;
bigInt >>= 2;
num >>= 1n;
num >>= 2;
bigInt &= 1n;
bigInt &= 2;
num &= 1n;
num &= 2;
bigInt ^= 1n;
bigInt ^= 2;
num ^= 1n;
num ^= 2;
bigInt |= 1n;
bigInt |= 2;
num |= 1n;
num |= 2;
bigInt = 1n + 2n;
num = 1 + 2;
1 + 2n;
1n + 2;
bigInt = 1n - 2n;
num = 1 - 2;
1 - 2n;
1n - 2;
bigInt = 1n * 2n;
num = 1 * 2;
1 * 2n;
1n * 2;
bigInt = 1n / 2n;
num = 1 / 2;
1 / 2n;
1n / 2;
bigInt = 1n % 2n;
num = 1 % 2;
1 % 2n;
1n % 2;
bigInt = Math.pow(1n, 2n);
num = Math.pow(1, 2);
Math.pow(1, 2n);
Math.pow(1n, 2);
bigInt = 1n & 2n;
num = 1 & 2;
1 & 2n;
1n & 2;
bigInt = 1n | 2n;
num = 1 | 2;
1 | 2n;
1n | 2;
bigInt = 1n ^ 2n;
num = 1 ^ 2;
1 ^ 2n;
1n ^ 2;
bigInt = 1n << 2n;
num = 1 << 2;
1 << 2n;
1n << 2;
bigInt = 1n >> 2n;
num = 1 >> 2;
1 >> 2n;
1n >> 2;
// Plus should still coerce to strings
var str;
str = "abc" + 123;
str = "abc" + 123n;
str = 123 + "abc";
str = 123n + "abc";
// Unary operations allowed on bigints and numbers
bigInt = bigInt++;
bigInt = ++bigInt;
num = num++;
num = ++num;
bigInt = bigInt--;
bigInt = --bigInt;
num = num--;
num = --num;
bigInt = -bigInt;
num = -num;
bigInt = ~bigInt;
num = ~num;
// Number-only operations
bigInt >>>= 1n;
num >>>= 2;
bigInt = bigInt >>> 1n;
num = num >>> 2;
num = +bigInt;
num = +num;
num = +"3";
// Comparisons can be mixed
var result;
result = bigInt > num;
result = bigInt >= num;
result = bigInt < num;
result = bigInt <= num;
// Trying to compare for equality is likely an error (since 1 == "1" is disallowed)
result = bigInt == num;
result = bigInt != num;
result = bigInt === num;
result = bigInt !== num;
// Types of arithmetic operations on other types
num = "3" & 5;
num = Math.pow(2, false); // should error, but infer number
"3" & 5n;
Math.pow(2n, false); // should error, result in any
num = ~"3";
num = -false; // should infer number
var bigIntOrNumber;
bigIntOrNumber + bigIntOrNumber; // should error, result in any
bigIntOrNumber << bigIntOrNumber; // should error, result in any
if (typeof bigIntOrNumber === "bigint") {
// Allowed, as type is narrowed to bigint
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
}
if (typeof bigIntOrNumber === "number") {
// Allowed, as type is narrowed to number
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
}
+bigIntOrNumber; // should error, result in number
~bigIntOrNumber; // should infer number | bigint
bigIntOrNumber++; // should infer number | bigint
++bigIntOrNumber; // should infer number | bigint
var anyValue;
anyValue + anyValue; // should infer any
anyValue >>> anyValue; // should infer number
anyValue ^ anyValue; // should infer number
+anyValue; // should infer number
-anyValue; // should infer number
anyValue--; // should infer number
--anyValue; // should infer number
// Distinguishing numbers from bigints with typeof
var isBigInt = function (x) { return x; };
var isNumber = function (x) { return x; };
var zeroOrBigOne;
if (typeof zeroOrBigOne === "bigint")
isBigInt(zeroOrBigOne);
else
isNumber(zeroOrBigOne);
// Distinguishing truthy from falsy
var isOne = function (x) { return x; };
if (zeroOrBigOne)
isOne(zeroOrBigOne);
var bigZeroOrOne;
if (bigZeroOrOne)
isOne(bigZeroOrOne);

View File

@@ -0,0 +1,350 @@
=== tests/cases/compiler/numberVsBigIntOperations.ts ===
// Cannot mix bigints and numbers
let bigInt = 1n, num = 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n; bigInt = 2; num = 1n; num = 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt += 1n; bigInt += 2; num += 1n; num += 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt -= 1n; bigInt -= 2; num -= 1n; num -= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt *= 1n; bigInt *= 2; num *= 1n; num *= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt /= 1n; bigInt /= 2; num /= 1n; num /= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt %= 1n; bigInt %= 2; num %= 1n; num %= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt **= 1n; bigInt **= 2; num **= 1n; num **= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt <<= 1n; bigInt <<= 2; num <<= 1n; num <<= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt >>= 1n; bigInt >>= 2; num >>= 1n; num >>= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt &= 1n; bigInt &= 2; num &= 1n; num &= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt ^= 1n; bigInt ^= 2; num ^= 1n; num ^= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt |= 1n; bigInt |= 2; num |= 1n; num |= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n + 2n; num = 1 + 2; 1 + 2n; 1n + 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n - 2n; num = 1 - 2; 1 - 2n; 1n - 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n * 2n; num = 1 * 2; 1 * 2n; 1n * 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n / 2n; num = 1 / 2; 1 / 2n; 1n / 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n % 2n; num = 1 % 2; 1 % 2n; 1n % 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n ** 2n; num = 1 ** 2; 1 ** 2n; 1n ** 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n & 2n; num = 1 & 2; 1 & 2n; 1n & 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n | 2n; num = 1 | 2; 1 | 2n; 1n | 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n ^ 2n; num = 1 ^ 2; 1 ^ 2n; 1n ^ 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n << 2n; num = 1 << 2; 1 << 2n; 1n << 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = 1n >> 2n; num = 1 >> 2; 1 >> 2n; 1n >> 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
// Plus should still coerce to strings
let str: string;
>str : Symbol(str, Decl(numberVsBigIntOperations.ts, 27, 3))
str = "abc" + 123; str = "abc" + 123n; str = 123 + "abc"; str = 123n + "abc";
>str : Symbol(str, Decl(numberVsBigIntOperations.ts, 27, 3))
>str : Symbol(str, Decl(numberVsBigIntOperations.ts, 27, 3))
>str : Symbol(str, Decl(numberVsBigIntOperations.ts, 27, 3))
>str : Symbol(str, Decl(numberVsBigIntOperations.ts, 27, 3))
// Unary operations allowed on bigints and numbers
bigInt = bigInt++; bigInt = ++bigInt; num = num++; num = ++num;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = bigInt--; bigInt = --bigInt; num = num--; num = --num;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = -bigInt; num = -num;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = ~bigInt; num = ~num;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
// Number-only operations
bigInt >>>= 1n; num >>>= 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
bigInt = bigInt >>> 1n; num = num >>> 2;
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
num = +bigInt; num = +num; num = +"3";
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
// Comparisons can be mixed
let result: boolean;
>result : Symbol(result, Decl(numberVsBigIntOperations.ts, 42, 3))
result = bigInt > num;
>result : Symbol(result, Decl(numberVsBigIntOperations.ts, 42, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
result = bigInt >= num;
>result : Symbol(result, Decl(numberVsBigIntOperations.ts, 42, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
result = bigInt < num;
>result : Symbol(result, Decl(numberVsBigIntOperations.ts, 42, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
result = bigInt <= num;
>result : Symbol(result, Decl(numberVsBigIntOperations.ts, 42, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
// Trying to compare for equality is likely an error (since 1 == "1" is disallowed)
result = bigInt == num;
>result : Symbol(result, Decl(numberVsBigIntOperations.ts, 42, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
result = bigInt != num;
>result : Symbol(result, Decl(numberVsBigIntOperations.ts, 42, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
result = bigInt === num;
>result : Symbol(result, Decl(numberVsBigIntOperations.ts, 42, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
result = bigInt !== num;
>result : Symbol(result, Decl(numberVsBigIntOperations.ts, 42, 3))
>bigInt : Symbol(bigInt, Decl(numberVsBigIntOperations.ts, 1, 3))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
// Types of arithmetic operations on other types
num = "3" & 5; num = 2 ** false; // should error, but infer number
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
"3" & 5n; 2n ** false; // should error, result in any
num = ~"3"; num = -false; // should infer number
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
>num : Symbol(num, Decl(numberVsBigIntOperations.ts, 1, 16))
let bigIntOrNumber: bigint | number;
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
bigIntOrNumber + bigIntOrNumber; // should error, result in any
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
bigIntOrNumber << bigIntOrNumber; // should error, result in any
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
if (typeof bigIntOrNumber === "bigint") {
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
// Allowed, as type is narrowed to bigint
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
}
if (typeof bigIntOrNumber === "number") {
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
// Allowed, as type is narrowed to number
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
}
+bigIntOrNumber; // should error, result in number
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
~bigIntOrNumber; // should infer number | bigint
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
bigIntOrNumber++; // should infer number | bigint
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
++bigIntOrNumber; // should infer number | bigint
>bigIntOrNumber : Symbol(bigIntOrNumber, Decl(numberVsBigIntOperations.ts, 58, 3))
let anyValue: any;
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
anyValue + anyValue; // should infer any
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
anyValue >>> anyValue; // should infer number
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
anyValue ^ anyValue; // should infer number
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
+anyValue; // should infer number
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
-anyValue; // should infer number
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
anyValue--; // should infer number
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
--anyValue; // should infer number
>anyValue : Symbol(anyValue, Decl(numberVsBigIntOperations.ts, 73, 3))
// Distinguishing numbers from bigints with typeof
const isBigInt: (x: 0n | 1n) => bigint = (x: 0n | 1n) => x;
>isBigInt : Symbol(isBigInt, Decl(numberVsBigIntOperations.ts, 83, 5))
>x : Symbol(x, Decl(numberVsBigIntOperations.ts, 83, 17))
>x : Symbol(x, Decl(numberVsBigIntOperations.ts, 83, 42))
>x : Symbol(x, Decl(numberVsBigIntOperations.ts, 83, 42))
const isNumber: (x: 0 | 1) => number = (x: 0 | 1) => x;
>isNumber : Symbol(isNumber, Decl(numberVsBigIntOperations.ts, 84, 5))
>x : Symbol(x, Decl(numberVsBigIntOperations.ts, 84, 17))
>x : Symbol(x, Decl(numberVsBigIntOperations.ts, 84, 40))
>x : Symbol(x, Decl(numberVsBigIntOperations.ts, 84, 40))
const zeroOrBigOne: 0 | 1n;
>zeroOrBigOne : Symbol(zeroOrBigOne, Decl(numberVsBigIntOperations.ts, 85, 5))
if (typeof zeroOrBigOne === "bigint") isBigInt(zeroOrBigOne);
>zeroOrBigOne : Symbol(zeroOrBigOne, Decl(numberVsBigIntOperations.ts, 85, 5))
>isBigInt : Symbol(isBigInt, Decl(numberVsBigIntOperations.ts, 83, 5))
>zeroOrBigOne : Symbol(zeroOrBigOne, Decl(numberVsBigIntOperations.ts, 85, 5))
else isNumber(zeroOrBigOne);
>isNumber : Symbol(isNumber, Decl(numberVsBigIntOperations.ts, 84, 5))
>zeroOrBigOne : Symbol(zeroOrBigOne, Decl(numberVsBigIntOperations.ts, 85, 5))
// Distinguishing truthy from falsy
const isOne = (x: 1 | 1n) => x;
>isOne : Symbol(isOne, Decl(numberVsBigIntOperations.ts, 90, 5))
>x : Symbol(x, Decl(numberVsBigIntOperations.ts, 90, 15))
>x : Symbol(x, Decl(numberVsBigIntOperations.ts, 90, 15))
if (zeroOrBigOne) isOne(zeroOrBigOne);
>zeroOrBigOne : Symbol(zeroOrBigOne, Decl(numberVsBigIntOperations.ts, 85, 5))
>isOne : Symbol(isOne, Decl(numberVsBigIntOperations.ts, 90, 5))
>zeroOrBigOne : Symbol(zeroOrBigOne, Decl(numberVsBigIntOperations.ts, 85, 5))
const bigZeroOrOne: 0n | 1;
>bigZeroOrOne : Symbol(bigZeroOrOne, Decl(numberVsBigIntOperations.ts, 92, 5))
if (bigZeroOrOne) isOne(bigZeroOrOne);
>bigZeroOrOne : Symbol(bigZeroOrOne, Decl(numberVsBigIntOperations.ts, 92, 5))
>isOne : Symbol(isOne, Decl(numberVsBigIntOperations.ts, 90, 5))
>bigZeroOrOne : Symbol(bigZeroOrOne, Decl(numberVsBigIntOperations.ts, 92, 5))

View File

@@ -0,0 +1,729 @@
=== tests/cases/compiler/numberVsBigIntOperations.ts ===
// Cannot mix bigints and numbers
let bigInt = 1n, num = 2;
>bigInt : bigint
>1n : 1n
>num : number
>2 : 2
bigInt = 1n; bigInt = 2; num = 1n; num = 2;
>bigInt = 1n : 1n
>bigInt : bigint
>1n : 1n
>bigInt = 2 : 2
>bigInt : bigint
>2 : 2
>num = 1n : 1n
>num : number
>1n : 1n
>num = 2 : 2
>num : number
>2 : 2
bigInt += 1n; bigInt += 2; num += 1n; num += 2;
>bigInt += 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt += 2 : any
>bigInt : bigint
>2 : 2
>num += 1n : any
>num : number
>1n : 1n
>num += 2 : number
>num : number
>2 : 2
bigInt -= 1n; bigInt -= 2; num -= 1n; num -= 2;
>bigInt -= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt -= 2 : any
>bigInt : bigint
>2 : 2
>num -= 1n : any
>num : number
>1n : 1n
>num -= 2 : number
>num : number
>2 : 2
bigInt *= 1n; bigInt *= 2; num *= 1n; num *= 2;
>bigInt *= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt *= 2 : any
>bigInt : bigint
>2 : 2
>num *= 1n : any
>num : number
>1n : 1n
>num *= 2 : number
>num : number
>2 : 2
bigInt /= 1n; bigInt /= 2; num /= 1n; num /= 2;
>bigInt /= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt /= 2 : any
>bigInt : bigint
>2 : 2
>num /= 1n : any
>num : number
>1n : 1n
>num /= 2 : number
>num : number
>2 : 2
bigInt %= 1n; bigInt %= 2; num %= 1n; num %= 2;
>bigInt %= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt %= 2 : any
>bigInt : bigint
>2 : 2
>num %= 1n : any
>num : number
>1n : 1n
>num %= 2 : number
>num : number
>2 : 2
bigInt **= 1n; bigInt **= 2; num **= 1n; num **= 2;
>bigInt **= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt **= 2 : any
>bigInt : bigint
>2 : 2
>num **= 1n : any
>num : number
>1n : 1n
>num **= 2 : number
>num : number
>2 : 2
bigInt <<= 1n; bigInt <<= 2; num <<= 1n; num <<= 2;
>bigInt <<= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt <<= 2 : any
>bigInt : bigint
>2 : 2
>num <<= 1n : any
>num : number
>1n : 1n
>num <<= 2 : number
>num : number
>2 : 2
bigInt >>= 1n; bigInt >>= 2; num >>= 1n; num >>= 2;
>bigInt >>= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt >>= 2 : any
>bigInt : bigint
>2 : 2
>num >>= 1n : any
>num : number
>1n : 1n
>num >>= 2 : number
>num : number
>2 : 2
bigInt &= 1n; bigInt &= 2; num &= 1n; num &= 2;
>bigInt &= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt &= 2 : any
>bigInt : bigint
>2 : 2
>num &= 1n : any
>num : number
>1n : 1n
>num &= 2 : number
>num : number
>2 : 2
bigInt ^= 1n; bigInt ^= 2; num ^= 1n; num ^= 2;
>bigInt ^= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt ^= 2 : any
>bigInt : bigint
>2 : 2
>num ^= 1n : any
>num : number
>1n : 1n
>num ^= 2 : number
>num : number
>2 : 2
bigInt |= 1n; bigInt |= 2; num |= 1n; num |= 2;
>bigInt |= 1n : bigint
>bigInt : bigint
>1n : 1n
>bigInt |= 2 : any
>bigInt : bigint
>2 : 2
>num |= 1n : any
>num : number
>1n : 1n
>num |= 2 : number
>num : number
>2 : 2
bigInt = 1n + 2n; num = 1 + 2; 1 + 2n; 1n + 2;
>bigInt = 1n + 2n : bigint
>bigInt : bigint
>1n + 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 + 2 : number
>num : number
>1 + 2 : number
>1 : 1
>2 : 2
>1 + 2n : any
>1 : 1
>2n : 2n
>1n + 2 : any
>1n : 1n
>2 : 2
bigInt = 1n - 2n; num = 1 - 2; 1 - 2n; 1n - 2;
>bigInt = 1n - 2n : bigint
>bigInt : bigint
>1n - 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 - 2 : number
>num : number
>1 - 2 : number
>1 : 1
>2 : 2
>1 - 2n : any
>1 : 1
>2n : 2n
>1n - 2 : any
>1n : 1n
>2 : 2
bigInt = 1n * 2n; num = 1 * 2; 1 * 2n; 1n * 2;
>bigInt = 1n * 2n : bigint
>bigInt : bigint
>1n * 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 * 2 : number
>num : number
>1 * 2 : number
>1 : 1
>2 : 2
>1 * 2n : any
>1 : 1
>2n : 2n
>1n * 2 : any
>1n : 1n
>2 : 2
bigInt = 1n / 2n; num = 1 / 2; 1 / 2n; 1n / 2;
>bigInt = 1n / 2n : bigint
>bigInt : bigint
>1n / 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 / 2 : number
>num : number
>1 / 2 : number
>1 : 1
>2 : 2
>1 / 2n : any
>1 : 1
>2n : 2n
>1n / 2 : any
>1n : 1n
>2 : 2
bigInt = 1n % 2n; num = 1 % 2; 1 % 2n; 1n % 2;
>bigInt = 1n % 2n : bigint
>bigInt : bigint
>1n % 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 % 2 : number
>num : number
>1 % 2 : number
>1 : 1
>2 : 2
>1 % 2n : any
>1 : 1
>2n : 2n
>1n % 2 : any
>1n : 1n
>2 : 2
bigInt = 1n ** 2n; num = 1 ** 2; 1 ** 2n; 1n ** 2;
>bigInt = 1n ** 2n : bigint
>bigInt : bigint
>1n ** 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 ** 2 : number
>num : number
>1 ** 2 : number
>1 : 1
>2 : 2
>1 ** 2n : any
>1 : 1
>2n : 2n
>1n ** 2 : any
>1n : 1n
>2 : 2
bigInt = 1n & 2n; num = 1 & 2; 1 & 2n; 1n & 2;
>bigInt = 1n & 2n : bigint
>bigInt : bigint
>1n & 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 & 2 : number
>num : number
>1 & 2 : number
>1 : 1
>2 : 2
>1 & 2n : any
>1 : 1
>2n : 2n
>1n & 2 : any
>1n : 1n
>2 : 2
bigInt = 1n | 2n; num = 1 | 2; 1 | 2n; 1n | 2;
>bigInt = 1n | 2n : bigint
>bigInt : bigint
>1n | 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 | 2 : number
>num : number
>1 | 2 : number
>1 : 1
>2 : 2
>1 | 2n : any
>1 : 1
>2n : 2n
>1n | 2 : any
>1n : 1n
>2 : 2
bigInt = 1n ^ 2n; num = 1 ^ 2; 1 ^ 2n; 1n ^ 2;
>bigInt = 1n ^ 2n : bigint
>bigInt : bigint
>1n ^ 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 ^ 2 : number
>num : number
>1 ^ 2 : number
>1 : 1
>2 : 2
>1 ^ 2n : any
>1 : 1
>2n : 2n
>1n ^ 2 : any
>1n : 1n
>2 : 2
bigInt = 1n << 2n; num = 1 << 2; 1 << 2n; 1n << 2;
>bigInt = 1n << 2n : bigint
>bigInt : bigint
>1n << 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 << 2 : number
>num : number
>1 << 2 : number
>1 : 1
>2 : 2
>1 << 2n : any
>1 : 1
>2n : 2n
>1n << 2 : any
>1n : 1n
>2 : 2
bigInt = 1n >> 2n; num = 1 >> 2; 1 >> 2n; 1n >> 2;
>bigInt = 1n >> 2n : bigint
>bigInt : bigint
>1n >> 2n : bigint
>1n : 1n
>2n : 2n
>num = 1 >> 2 : number
>num : number
>1 >> 2 : number
>1 : 1
>2 : 2
>1 >> 2n : any
>1 : 1
>2n : 2n
>1n >> 2 : any
>1n : 1n
>2 : 2
// Plus should still coerce to strings
let str: string;
>str : string
str = "abc" + 123; str = "abc" + 123n; str = 123 + "abc"; str = 123n + "abc";
>str = "abc" + 123 : string
>str : string
>"abc" + 123 : string
>"abc" : "abc"
>123 : 123
>str = "abc" + 123n : string
>str : string
>"abc" + 123n : string
>"abc" : "abc"
>123n : 123n
>str = 123 + "abc" : string
>str : string
>123 + "abc" : string
>123 : 123
>"abc" : "abc"
>str = 123n + "abc" : string
>str : string
>123n + "abc" : string
>123n : 123n
>"abc" : "abc"
// Unary operations allowed on bigints and numbers
bigInt = bigInt++; bigInt = ++bigInt; num = num++; num = ++num;
>bigInt = bigInt++ : bigint
>bigInt : bigint
>bigInt++ : bigint
>bigInt : bigint
>bigInt = ++bigInt : bigint
>bigInt : bigint
>++bigInt : bigint
>bigInt : bigint
>num = num++ : number
>num : number
>num++ : number
>num : number
>num = ++num : number
>num : number
>++num : number
>num : number
bigInt = bigInt--; bigInt = --bigInt; num = num--; num = --num;
>bigInt = bigInt-- : bigint
>bigInt : bigint
>bigInt-- : bigint
>bigInt : bigint
>bigInt = --bigInt : bigint
>bigInt : bigint
>--bigInt : bigint
>bigInt : bigint
>num = num-- : number
>num : number
>num-- : number
>num : number
>num = --num : number
>num : number
>--num : number
>num : number
bigInt = -bigInt; num = -num;
>bigInt = -bigInt : bigint
>bigInt : bigint
>-bigInt : bigint
>bigInt : bigint
>num = -num : number
>num : number
>-num : number
>num : number
bigInt = ~bigInt; num = ~num;
>bigInt = ~bigInt : bigint
>bigInt : bigint
>~bigInt : bigint
>bigInt : bigint
>num = ~num : number
>num : number
>~num : number
>num : number
// Number-only operations
bigInt >>>= 1n; num >>>= 2;
>bigInt >>>= 1n : bigint
>bigInt : bigint
>1n : 1n
>num >>>= 2 : number
>num : number
>2 : 2
bigInt = bigInt >>> 1n; num = num >>> 2;
>bigInt = bigInt >>> 1n : bigint
>bigInt : bigint
>bigInt >>> 1n : bigint
>bigInt : bigint
>1n : 1n
>num = num >>> 2 : number
>num : number
>num >>> 2 : number
>num : number
>2 : 2
num = +bigInt; num = +num; num = +"3";
>num = +bigInt : number
>num : number
>+bigInt : number
>bigInt : bigint
>num = +num : number
>num : number
>+num : number
>num : number
>num = +"3" : number
>num : number
>+"3" : number
>"3" : "3"
// Comparisons can be mixed
let result: boolean;
>result : boolean
result = bigInt > num;
>result = bigInt > num : boolean
>result : boolean
>bigInt > num : boolean
>bigInt : bigint
>num : number
result = bigInt >= num;
>result = bigInt >= num : boolean
>result : boolean
>bigInt >= num : boolean
>bigInt : bigint
>num : number
result = bigInt < num;
>result = bigInt < num : boolean
>result : boolean
>bigInt < num : boolean
>bigInt : bigint
>num : number
result = bigInt <= num;
>result = bigInt <= num : boolean
>result : boolean
>bigInt <= num : boolean
>bigInt : bigint
>num : number
// Trying to compare for equality is likely an error (since 1 == "1" is disallowed)
result = bigInt == num;
>result = bigInt == num : boolean
>result : boolean
>bigInt == num : boolean
>bigInt : bigint
>num : number
result = bigInt != num;
>result = bigInt != num : boolean
>result : boolean
>bigInt != num : boolean
>bigInt : bigint
>num : number
result = bigInt === num;
>result = bigInt === num : boolean
>result : boolean
>bigInt === num : boolean
>bigInt : bigint
>num : number
result = bigInt !== num;
>result = bigInt !== num : boolean
>result : boolean
>bigInt !== num : boolean
>bigInt : bigint
>num : number
// Types of arithmetic operations on other types
num = "3" & 5; num = 2 ** false; // should error, but infer number
>num = "3" & 5 : number
>num : number
>"3" & 5 : number
>"3" : "3"
>5 : 5
>num = 2 ** false : number
>num : number
>2 ** false : number
>2 : 2
>false : false
"3" & 5n; 2n ** false; // should error, result in any
>"3" & 5n : any
>"3" : "3"
>5n : 5n
>2n ** false : any
>2n : 2n
>false : false
num = ~"3"; num = -false; // should infer number
>num = ~"3" : number
>num : number
>~"3" : number
>"3" : "3"
>num = -false : number
>num : number
>-false : number
>false : false
let bigIntOrNumber: bigint | number;
>bigIntOrNumber : number | bigint
bigIntOrNumber + bigIntOrNumber; // should error, result in any
>bigIntOrNumber + bigIntOrNumber : any
>bigIntOrNumber : number | bigint
>bigIntOrNumber : number | bigint
bigIntOrNumber << bigIntOrNumber; // should error, result in any
>bigIntOrNumber << bigIntOrNumber : any
>bigIntOrNumber : number | bigint
>bigIntOrNumber : number | bigint
if (typeof bigIntOrNumber === "bigint") {
>typeof bigIntOrNumber === "bigint" : boolean
>typeof bigIntOrNumber : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>bigIntOrNumber : number | bigint
>"bigint" : "bigint"
// Allowed, as type is narrowed to bigint
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
>bigIntOrNumber = bigIntOrNumber << bigIntOrNumber : bigint
>bigIntOrNumber : number | bigint
>bigIntOrNumber << bigIntOrNumber : bigint
>bigIntOrNumber : bigint
>bigIntOrNumber : bigint
}
if (typeof bigIntOrNumber === "number") {
>typeof bigIntOrNumber === "number" : boolean
>typeof bigIntOrNumber : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>bigIntOrNumber : number | bigint
>"number" : "number"
// Allowed, as type is narrowed to number
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
>bigIntOrNumber = bigIntOrNumber << bigIntOrNumber : number
>bigIntOrNumber : number | bigint
>bigIntOrNumber << bigIntOrNumber : number
>bigIntOrNumber : number
>bigIntOrNumber : number
}
+bigIntOrNumber; // should error, result in number
>+bigIntOrNumber : number
>bigIntOrNumber : number | bigint
~bigIntOrNumber; // should infer number | bigint
>~bigIntOrNumber : number | bigint
>bigIntOrNumber : number | bigint
bigIntOrNumber++; // should infer number | bigint
>bigIntOrNumber++ : number | bigint
>bigIntOrNumber : number | bigint
++bigIntOrNumber; // should infer number | bigint
>++bigIntOrNumber : number | bigint
>bigIntOrNumber : number | bigint
let anyValue: any;
>anyValue : any
anyValue + anyValue; // should infer any
>anyValue + anyValue : any
>anyValue : any
>anyValue : any
anyValue >>> anyValue; // should infer number
>anyValue >>> anyValue : number
>anyValue : any
>anyValue : any
anyValue ^ anyValue; // should infer number
>anyValue ^ anyValue : number
>anyValue : any
>anyValue : any
+anyValue; // should infer number
>+anyValue : number
>anyValue : any
-anyValue; // should infer number
>-anyValue : number
>anyValue : any
anyValue--; // should infer number
>anyValue-- : number
>anyValue : any
--anyValue; // should infer number
>--anyValue : number
>anyValue : any
// Distinguishing numbers from bigints with typeof
const isBigInt: (x: 0n | 1n) => bigint = (x: 0n | 1n) => x;
>isBigInt : (x: 0n | 1n) => bigint
>x : 0n | 1n
>(x: 0n | 1n) => x : (x: 0n | 1n) => 0n | 1n
>x : 0n | 1n
>x : 0n | 1n
const isNumber: (x: 0 | 1) => number = (x: 0 | 1) => x;
>isNumber : (x: 0 | 1) => number
>x : 0 | 1
>(x: 0 | 1) => x : (x: 0 | 1) => 0 | 1
>x : 0 | 1
>x : 0 | 1
const zeroOrBigOne: 0 | 1n;
>zeroOrBigOne : 0 | 1n
if (typeof zeroOrBigOne === "bigint") isBigInt(zeroOrBigOne);
>typeof zeroOrBigOne === "bigint" : boolean
>typeof zeroOrBigOne : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>zeroOrBigOne : 0 | 1n
>"bigint" : "bigint"
>isBigInt(zeroOrBigOne) : bigint
>isBigInt : (x: 0n | 1n) => bigint
>zeroOrBigOne : 1n
else isNumber(zeroOrBigOne);
>isNumber(zeroOrBigOne) : number
>isNumber : (x: 0 | 1) => number
>zeroOrBigOne : 0
// Distinguishing truthy from falsy
const isOne = (x: 1 | 1n) => x;
>isOne : (x: 1n | 1) => 1n | 1
>(x: 1 | 1n) => x : (x: 1n | 1) => 1n | 1
>x : 1n | 1
>x : 1n | 1
if (zeroOrBigOne) isOne(zeroOrBigOne);
>zeroOrBigOne : 0 | 1n
>isOne(zeroOrBigOne) : 1n | 1
>isOne : (x: 1n | 1) => 1n | 1
>zeroOrBigOne : 1n
const bigZeroOrOne: 0n | 1;
>bigZeroOrOne : 0n | 1
if (bigZeroOrOne) isOne(bigZeroOrOne);
>bigZeroOrOne : 0n | 1
>isOne(bigZeroOrOne) : 1n | 1
>isOne : (x: 1n | 1) => 1n | 1
>bigZeroOrOne : 1

View File

@@ -0,0 +1,124 @@
tests/cases/compiler/parseBigInt.ts(51,20): error TS2735: Operator '+' cannot be applied to type '123n'.
tests/cases/compiler/parseBigInt.ts(52,23): error TS2735: Operator '+' cannot be applied to type '291n'.
tests/cases/compiler/parseBigInt.ts(56,25): error TS1005: ',' expected.
tests/cases/compiler/parseBigInt.ts(57,25): error TS1005: ',' expected.
tests/cases/compiler/parseBigInt.ts(58,22): error TS1005: ',' expected.
tests/cases/compiler/parseBigInt.ts(59,28): error TS1005: ',' expected.
tests/cases/compiler/parseBigInt.ts(60,23): error TS1177: Binary digit expected.
tests/cases/compiler/parseBigInt.ts(61,20): error TS1178: Octal digit expected.
tests/cases/compiler/parseBigInt.ts(62,20): error TS1125: Hexadecimal digit expected.
tests/cases/compiler/parseBigInt.ts(63,26): error TS2304: Cannot find name '_123n'.
tests/cases/compiler/parseBigInt.ts(64,30): error TS6188: Numeric separators are not allowed here.
tests/cases/compiler/parseBigInt.ts(65,33): error TS6189: Multiple consecutive numeric separators are not permitted.
tests/cases/compiler/parseBigInt.ts(69,15): error TS2345: Argument of type '0n' is not assignable to parameter of type '1n | 3n | 2n'.
tests/cases/compiler/parseBigInt.ts(70,15): error TS2345: Argument of type '0' is not assignable to parameter of type '1n | 3n | 2n'.
tests/cases/compiler/parseBigInt.ts(70,34): error TS2345: Argument of type '1' is not assignable to parameter of type '1n | 3n | 2n'.
tests/cases/compiler/parseBigInt.ts(70,53): error TS2345: Argument of type '2' is not assignable to parameter of type '1n | 3n | 2n'.
tests/cases/compiler/parseBigInt.ts(70,72): error TS2345: Argument of type '3' is not assignable to parameter of type '1n | 3n | 2n'.
==== tests/cases/compiler/parseBigInt.ts (17 errors) ====
// All bases should allow "n" suffix
const bin = 0b101, binBig = 0b101n; // 5, 5n
const oct = 0o567, octBig = 0o567n; // 375, 375n
const hex = 0xC0B, hexBig = 0xC0Bn; // 3083, 3083n
const dec = 123, decBig = 123n;
// Test literals whose values overflow a 53-bit integer
// These should be represented exactly in the emitted JS
const largeBin = 0b10101010101010101010101010101010101010101010101010101010101n; // 384307168202282325n
const largeOct = 0o123456712345671234567n; // 1505852261029722487n
const largeDec = 12345678091234567890n;
const largeHex = 0x1234567890abcdefn; // 1311768467294899695n
// Test literals with separators
const separatedBin = 0b010_10_1n; // 21n
const separatedOct = 0o1234_567n; // 342391n
const separatedDec = 123_456_789n;
const separatedHex = 0x0_abcdefn; // 11259375n
// Test parsing literals of different bit sizes
// to ensure that parsePseudoBigInt() allocates enough space
const zero = 0b0n;
const oneBit = 0b1n;
const twoBit = 0b11n; // 3n
const threeBit = 0b111n; // 7n
const fourBit = 0b1111n; // 15n
const fiveBit = 0b11111n; // 31n
const sixBit = 0b111111n; // 63n
const sevenBit = 0b1111111n; // 127n
const eightBit = 0b11111111n; // 255n
const nineBit = 0b111111111n; // 511n
const tenBit = 0b1111111111n; // 1023n
const elevenBit = 0b11111111111n; // 2047n
const twelveBit = 0b111111111111n; // 4095n
const thirteenBit = 0b1111111111111n; // 8191n
const fourteenBit = 0b11111111111111n; // 16383n
const fifteenBit = 0b111111111111111n; // 32767n
const sixteenBit = 0b1111111111111111n; // 65535n
const seventeenBit = 0b11111111111111111n; // 131071n
// Test negative literals
const neg = -123n;
const negHex: -16n = -0x10n;
// Test normalization of bigints -- all of these should succeed
const negZero: 0n = -0n;
const baseChange: 255n = 0xFFn;
const leadingZeros: 0xFFn = 0x000000FFn;
// Plus not allowed on literals
const unaryPlus = +123n;
~~~~
!!! error TS2735: Operator '+' cannot be applied to type '123n'.
const unaryPlusHex = +0x123n;
~~~~~~
!!! error TS2735: Operator '+' cannot be applied to type '291n'.
// Parsing errors
// In separate blocks because they each declare an "n" variable
{ const legacyOct = 0123n; }
~
!!! error TS1005: ',' expected.
{ const scientific = 1e2n; }
~
!!! error TS1005: ',' expected.
{ const decimal = 4.1n; }
~
!!! error TS1005: ',' expected.
{ const leadingDecimal = .1n; }
~
!!! error TS1005: ',' expected.
const emptyBinary = 0bn; // should error but infer 0n
!!! error TS1177: Binary digit expected.
const emptyOct = 0on; // should error but infer 0n
!!! error TS1178: Octal digit expected.
const emptyHex = 0xn; // should error but infer 0n
!!! error TS1125: Hexadecimal digit expected.
const leadingSeparator = _123n;
~~~~~
!!! error TS2304: Cannot find name '_123n'.
const trailingSeparator = 123_n;
~
!!! error TS6188: Numeric separators are not allowed here.
const doubleSeparator = 123_456__789n;
~
!!! error TS6189: Multiple consecutive numeric separators are not permitted.
// Using literals as types
const oneTwoOrThree = (x: 1n | 2n | 3n): bigint => x ** 2n;
oneTwoOrThree(0n); oneTwoOrThree(1n); oneTwoOrThree(2n); oneTwoOrThree(3n);
~~
!!! error TS2345: Argument of type '0n' is not assignable to parameter of type '1n | 3n | 2n'.
oneTwoOrThree(0); oneTwoOrThree(1); oneTwoOrThree(2); oneTwoOrThree(3);
~
!!! error TS2345: Argument of type '0' is not assignable to parameter of type '1n | 3n | 2n'.
~
!!! error TS2345: Argument of type '1' is not assignable to parameter of type '1n | 3n | 2n'.
~
!!! error TS2345: Argument of type '2' is not assignable to parameter of type '1n | 3n | 2n'.
~
!!! error TS2345: Argument of type '3' is not assignable to parameter of type '1n | 3n | 2n'.

View File

@@ -0,0 +1,149 @@
//// [parseBigInt.ts]
// All bases should allow "n" suffix
const bin = 0b101, binBig = 0b101n; // 5, 5n
const oct = 0o567, octBig = 0o567n; // 375, 375n
const hex = 0xC0B, hexBig = 0xC0Bn; // 3083, 3083n
const dec = 123, decBig = 123n;
// Test literals whose values overflow a 53-bit integer
// These should be represented exactly in the emitted JS
const largeBin = 0b10101010101010101010101010101010101010101010101010101010101n; // 384307168202282325n
const largeOct = 0o123456712345671234567n; // 1505852261029722487n
const largeDec = 12345678091234567890n;
const largeHex = 0x1234567890abcdefn; // 1311768467294899695n
// Test literals with separators
const separatedBin = 0b010_10_1n; // 21n
const separatedOct = 0o1234_567n; // 342391n
const separatedDec = 123_456_789n;
const separatedHex = 0x0_abcdefn; // 11259375n
// Test parsing literals of different bit sizes
// to ensure that parsePseudoBigInt() allocates enough space
const zero = 0b0n;
const oneBit = 0b1n;
const twoBit = 0b11n; // 3n
const threeBit = 0b111n; // 7n
const fourBit = 0b1111n; // 15n
const fiveBit = 0b11111n; // 31n
const sixBit = 0b111111n; // 63n
const sevenBit = 0b1111111n; // 127n
const eightBit = 0b11111111n; // 255n
const nineBit = 0b111111111n; // 511n
const tenBit = 0b1111111111n; // 1023n
const elevenBit = 0b11111111111n; // 2047n
const twelveBit = 0b111111111111n; // 4095n
const thirteenBit = 0b1111111111111n; // 8191n
const fourteenBit = 0b11111111111111n; // 16383n
const fifteenBit = 0b111111111111111n; // 32767n
const sixteenBit = 0b1111111111111111n; // 65535n
const seventeenBit = 0b11111111111111111n; // 131071n
// Test negative literals
const neg = -123n;
const negHex: -16n = -0x10n;
// Test normalization of bigints -- all of these should succeed
const negZero: 0n = -0n;
const baseChange: 255n = 0xFFn;
const leadingZeros: 0xFFn = 0x000000FFn;
// Plus not allowed on literals
const unaryPlus = +123n;
const unaryPlusHex = +0x123n;
// Parsing errors
// In separate blocks because they each declare an "n" variable
{ const legacyOct = 0123n; }
{ const scientific = 1e2n; }
{ const decimal = 4.1n; }
{ const leadingDecimal = .1n; }
const emptyBinary = 0bn; // should error but infer 0n
const emptyOct = 0on; // should error but infer 0n
const emptyHex = 0xn; // should error but infer 0n
const leadingSeparator = _123n;
const trailingSeparator = 123_n;
const doubleSeparator = 123_456__789n;
// Using literals as types
const oneTwoOrThree = (x: 1n | 2n | 3n): bigint => x ** 2n;
oneTwoOrThree(0n); oneTwoOrThree(1n); oneTwoOrThree(2n); oneTwoOrThree(3n);
oneTwoOrThree(0); oneTwoOrThree(1); oneTwoOrThree(2); oneTwoOrThree(3);
//// [parseBigInt.js]
// All bases should allow "n" suffix
var bin = 5, binBig = 5n; // 5, 5n
var oct = 375, octBig = 375n; // 375, 375n
var hex = 0xC0B, hexBig = 0xC0Bn; // 3083, 3083n
var dec = 123, decBig = 123n;
// Test literals whose values overflow a 53-bit integer
// These should be represented exactly in the emitted JS
var largeBin = 384307168202282325n; // 384307168202282325n
var largeOct = 1505852261029722487n; // 1505852261029722487n
var largeDec = 12345678091234567890n;
var largeHex = 0x1234567890abcdefn; // 1311768467294899695n
// Test literals with separators
var separatedBin = 21n; // 21n
var separatedOct = 342391n; // 342391n
var separatedDec = 123456789n;
var separatedHex = 0x0abcdefn; // 11259375n
// Test parsing literals of different bit sizes
// to ensure that parsePseudoBigInt() allocates enough space
var zero = 0n;
var oneBit = 1n;
var twoBit = 3n; // 3n
var threeBit = 7n; // 7n
var fourBit = 15n; // 15n
var fiveBit = 31n; // 31n
var sixBit = 63n; // 63n
var sevenBit = 127n; // 127n
var eightBit = 255n; // 255n
var nineBit = 511n; // 511n
var tenBit = 1023n; // 1023n
var elevenBit = 2047n; // 2047n
var twelveBit = 4095n; // 4095n
var thirteenBit = 8191n; // 8191n
var fourteenBit = 16383n; // 16383n
var fifteenBit = 32767n; // 32767n
var sixteenBit = 65535n; // 65535n
var seventeenBit = 131071n; // 131071n
// Test negative literals
var neg = -123n;
var negHex = -0x10n;
// Test normalization of bigints -- all of these should succeed
var negZero = -0n;
var baseChange = 0xFFn;
var leadingZeros = 0x000000FFn;
// Plus not allowed on literals
var unaryPlus = +123n;
var unaryPlusHex = +0x123n;
// Parsing errors
// In separate blocks because they each declare an "n" variable
{
var legacyOct = 0123, n;
}
{
var scientific = 1e2, n;
}
{
var decimal = 4.1, n;
}
{
var leadingDecimal = .1, n;
}
var emptyBinary = 0n; // should error but infer 0n
var emptyOct = 0n; // should error but infer 0n
var emptyHex = 0xn; // should error but infer 0n
var leadingSeparator = _123n;
var trailingSeparator = 123n;
var doubleSeparator = 123456789n;
// Using literals as types
var oneTwoOrThree = function (x) { return Math.pow(x, 2n); };
oneTwoOrThree(0n);
oneTwoOrThree(1n);
oneTwoOrThree(2n);
oneTwoOrThree(3n);
oneTwoOrThree(0);
oneTwoOrThree(1);
oneTwoOrThree(2);
oneTwoOrThree(3);

View File

@@ -0,0 +1,179 @@
=== tests/cases/compiler/parseBigInt.ts ===
// All bases should allow "n" suffix
const bin = 0b101, binBig = 0b101n; // 5, 5n
>bin : Symbol(bin, Decl(parseBigInt.ts, 1, 5))
>binBig : Symbol(binBig, Decl(parseBigInt.ts, 1, 18))
const oct = 0o567, octBig = 0o567n; // 375, 375n
>oct : Symbol(oct, Decl(parseBigInt.ts, 2, 5))
>octBig : Symbol(octBig, Decl(parseBigInt.ts, 2, 18))
const hex = 0xC0B, hexBig = 0xC0Bn; // 3083, 3083n
>hex : Symbol(hex, Decl(parseBigInt.ts, 3, 5))
>hexBig : Symbol(hexBig, Decl(parseBigInt.ts, 3, 18))
const dec = 123, decBig = 123n;
>dec : Symbol(dec, Decl(parseBigInt.ts, 4, 5))
>decBig : Symbol(decBig, Decl(parseBigInt.ts, 4, 16))
// Test literals whose values overflow a 53-bit integer
// These should be represented exactly in the emitted JS
const largeBin = 0b10101010101010101010101010101010101010101010101010101010101n; // 384307168202282325n
>largeBin : Symbol(largeBin, Decl(parseBigInt.ts, 8, 5))
const largeOct = 0o123456712345671234567n; // 1505852261029722487n
>largeOct : Symbol(largeOct, Decl(parseBigInt.ts, 9, 5))
const largeDec = 12345678091234567890n;
>largeDec : Symbol(largeDec, Decl(parseBigInt.ts, 10, 5))
const largeHex = 0x1234567890abcdefn; // 1311768467294899695n
>largeHex : Symbol(largeHex, Decl(parseBigInt.ts, 11, 5))
// Test literals with separators
const separatedBin = 0b010_10_1n; // 21n
>separatedBin : Symbol(separatedBin, Decl(parseBigInt.ts, 14, 5))
const separatedOct = 0o1234_567n; // 342391n
>separatedOct : Symbol(separatedOct, Decl(parseBigInt.ts, 15, 5))
const separatedDec = 123_456_789n;
>separatedDec : Symbol(separatedDec, Decl(parseBigInt.ts, 16, 5))
const separatedHex = 0x0_abcdefn; // 11259375n
>separatedHex : Symbol(separatedHex, Decl(parseBigInt.ts, 17, 5))
// Test parsing literals of different bit sizes
// to ensure that parsePseudoBigInt() allocates enough space
const zero = 0b0n;
>zero : Symbol(zero, Decl(parseBigInt.ts, 21, 5))
const oneBit = 0b1n;
>oneBit : Symbol(oneBit, Decl(parseBigInt.ts, 22, 5))
const twoBit = 0b11n; // 3n
>twoBit : Symbol(twoBit, Decl(parseBigInt.ts, 23, 5))
const threeBit = 0b111n; // 7n
>threeBit : Symbol(threeBit, Decl(parseBigInt.ts, 24, 5))
const fourBit = 0b1111n; // 15n
>fourBit : Symbol(fourBit, Decl(parseBigInt.ts, 25, 5))
const fiveBit = 0b11111n; // 31n
>fiveBit : Symbol(fiveBit, Decl(parseBigInt.ts, 26, 5))
const sixBit = 0b111111n; // 63n
>sixBit : Symbol(sixBit, Decl(parseBigInt.ts, 27, 5))
const sevenBit = 0b1111111n; // 127n
>sevenBit : Symbol(sevenBit, Decl(parseBigInt.ts, 28, 5))
const eightBit = 0b11111111n; // 255n
>eightBit : Symbol(eightBit, Decl(parseBigInt.ts, 29, 5))
const nineBit = 0b111111111n; // 511n
>nineBit : Symbol(nineBit, Decl(parseBigInt.ts, 30, 5))
const tenBit = 0b1111111111n; // 1023n
>tenBit : Symbol(tenBit, Decl(parseBigInt.ts, 31, 5))
const elevenBit = 0b11111111111n; // 2047n
>elevenBit : Symbol(elevenBit, Decl(parseBigInt.ts, 32, 5))
const twelveBit = 0b111111111111n; // 4095n
>twelveBit : Symbol(twelveBit, Decl(parseBigInt.ts, 33, 5))
const thirteenBit = 0b1111111111111n; // 8191n
>thirteenBit : Symbol(thirteenBit, Decl(parseBigInt.ts, 34, 5))
const fourteenBit = 0b11111111111111n; // 16383n
>fourteenBit : Symbol(fourteenBit, Decl(parseBigInt.ts, 35, 5))
const fifteenBit = 0b111111111111111n; // 32767n
>fifteenBit : Symbol(fifteenBit, Decl(parseBigInt.ts, 36, 5))
const sixteenBit = 0b1111111111111111n; // 65535n
>sixteenBit : Symbol(sixteenBit, Decl(parseBigInt.ts, 37, 5))
const seventeenBit = 0b11111111111111111n; // 131071n
>seventeenBit : Symbol(seventeenBit, Decl(parseBigInt.ts, 38, 5))
// Test negative literals
const neg = -123n;
>neg : Symbol(neg, Decl(parseBigInt.ts, 41, 5))
const negHex: -16n = -0x10n;
>negHex : Symbol(negHex, Decl(parseBigInt.ts, 42, 5))
// Test normalization of bigints -- all of these should succeed
const negZero: 0n = -0n;
>negZero : Symbol(negZero, Decl(parseBigInt.ts, 45, 5))
const baseChange: 255n = 0xFFn;
>baseChange : Symbol(baseChange, Decl(parseBigInt.ts, 46, 5))
const leadingZeros: 0xFFn = 0x000000FFn;
>leadingZeros : Symbol(leadingZeros, Decl(parseBigInt.ts, 47, 5))
// Plus not allowed on literals
const unaryPlus = +123n;
>unaryPlus : Symbol(unaryPlus, Decl(parseBigInt.ts, 50, 5))
const unaryPlusHex = +0x123n;
>unaryPlusHex : Symbol(unaryPlusHex, Decl(parseBigInt.ts, 51, 5))
// Parsing errors
// In separate blocks because they each declare an "n" variable
{ const legacyOct = 0123n; }
>legacyOct : Symbol(legacyOct, Decl(parseBigInt.ts, 55, 7))
>n : Symbol(n, Decl(parseBigInt.ts, 55, 24))
{ const scientific = 1e2n; }
>scientific : Symbol(scientific, Decl(parseBigInt.ts, 56, 7))
>n : Symbol(n, Decl(parseBigInt.ts, 56, 24))
{ const decimal = 4.1n; }
>decimal : Symbol(decimal, Decl(parseBigInt.ts, 57, 7))
>n : Symbol(n, Decl(parseBigInt.ts, 57, 21))
{ const leadingDecimal = .1n; }
>leadingDecimal : Symbol(leadingDecimal, Decl(parseBigInt.ts, 58, 7))
>n : Symbol(n, Decl(parseBigInt.ts, 58, 27))
const emptyBinary = 0bn; // should error but infer 0n
>emptyBinary : Symbol(emptyBinary, Decl(parseBigInt.ts, 59, 5))
const emptyOct = 0on; // should error but infer 0n
>emptyOct : Symbol(emptyOct, Decl(parseBigInt.ts, 60, 5))
const emptyHex = 0xn; // should error but infer 0n
>emptyHex : Symbol(emptyHex, Decl(parseBigInt.ts, 61, 5))
const leadingSeparator = _123n;
>leadingSeparator : Symbol(leadingSeparator, Decl(parseBigInt.ts, 62, 5))
const trailingSeparator = 123_n;
>trailingSeparator : Symbol(trailingSeparator, Decl(parseBigInt.ts, 63, 5))
const doubleSeparator = 123_456__789n;
>doubleSeparator : Symbol(doubleSeparator, Decl(parseBigInt.ts, 64, 5))
// Using literals as types
const oneTwoOrThree = (x: 1n | 2n | 3n): bigint => x ** 2n;
>oneTwoOrThree : Symbol(oneTwoOrThree, Decl(parseBigInt.ts, 67, 5))
>x : Symbol(x, Decl(parseBigInt.ts, 67, 23))
>x : Symbol(x, Decl(parseBigInt.ts, 67, 23))
oneTwoOrThree(0n); oneTwoOrThree(1n); oneTwoOrThree(2n); oneTwoOrThree(3n);
>oneTwoOrThree : Symbol(oneTwoOrThree, Decl(parseBigInt.ts, 67, 5))
>oneTwoOrThree : Symbol(oneTwoOrThree, Decl(parseBigInt.ts, 67, 5))
>oneTwoOrThree : Symbol(oneTwoOrThree, Decl(parseBigInt.ts, 67, 5))
>oneTwoOrThree : Symbol(oneTwoOrThree, Decl(parseBigInt.ts, 67, 5))
oneTwoOrThree(0); oneTwoOrThree(1); oneTwoOrThree(2); oneTwoOrThree(3);
>oneTwoOrThree : Symbol(oneTwoOrThree, Decl(parseBigInt.ts, 67, 5))
>oneTwoOrThree : Symbol(oneTwoOrThree, Decl(parseBigInt.ts, 67, 5))
>oneTwoOrThree : Symbol(oneTwoOrThree, Decl(parseBigInt.ts, 67, 5))
>oneTwoOrThree : Symbol(oneTwoOrThree, Decl(parseBigInt.ts, 67, 5))

View File

@@ -0,0 +1,256 @@
=== tests/cases/compiler/parseBigInt.ts ===
// All bases should allow "n" suffix
const bin = 0b101, binBig = 0b101n; // 5, 5n
>bin : 5
>0b101 : 5
>binBig : 5n
>0b101n : 5n
const oct = 0o567, octBig = 0o567n; // 375, 375n
>oct : 375
>0o567 : 375
>octBig : 375n
>0o567n : 375n
const hex = 0xC0B, hexBig = 0xC0Bn; // 3083, 3083n
>hex : 3083
>0xC0B : 3083
>hexBig : 3083n
>0xC0Bn : 3083n
const dec = 123, decBig = 123n;
>dec : 123
>123 : 123
>decBig : 123n
>123n : 123n
// Test literals whose values overflow a 53-bit integer
// These should be represented exactly in the emitted JS
const largeBin = 0b10101010101010101010101010101010101010101010101010101010101n; // 384307168202282325n
>largeBin : 384307168202282325n
>0b10101010101010101010101010101010101010101010101010101010101n : 384307168202282325n
const largeOct = 0o123456712345671234567n; // 1505852261029722487n
>largeOct : 1505852261029722487n
>0o123456712345671234567n : 1505852261029722487n
const largeDec = 12345678091234567890n;
>largeDec : 12345678091234567890n
>12345678091234567890n : 12345678091234567890n
const largeHex = 0x1234567890abcdefn; // 1311768467294899695n
>largeHex : 1311768467294899695n
>0x1234567890abcdefn : 1311768467294899695n
// Test literals with separators
const separatedBin = 0b010_10_1n; // 21n
>separatedBin : 21n
>0b010_10_1n : 21n
const separatedOct = 0o1234_567n; // 342391n
>separatedOct : 342391n
>0o1234_567n : 342391n
const separatedDec = 123_456_789n;
>separatedDec : 123456789n
>123_456_789n : 123456789n
const separatedHex = 0x0_abcdefn; // 11259375n
>separatedHex : 11259375n
>0x0_abcdefn : 11259375n
// Test parsing literals of different bit sizes
// to ensure that parsePseudoBigInt() allocates enough space
const zero = 0b0n;
>zero : 0n
>0b0n : 0n
const oneBit = 0b1n;
>oneBit : 1n
>0b1n : 1n
const twoBit = 0b11n; // 3n
>twoBit : 3n
>0b11n : 3n
const threeBit = 0b111n; // 7n
>threeBit : 7n
>0b111n : 7n
const fourBit = 0b1111n; // 15n
>fourBit : 15n
>0b1111n : 15n
const fiveBit = 0b11111n; // 31n
>fiveBit : 31n
>0b11111n : 31n
const sixBit = 0b111111n; // 63n
>sixBit : 63n
>0b111111n : 63n
const sevenBit = 0b1111111n; // 127n
>sevenBit : 127n
>0b1111111n : 127n
const eightBit = 0b11111111n; // 255n
>eightBit : 255n
>0b11111111n : 255n
const nineBit = 0b111111111n; // 511n
>nineBit : 511n
>0b111111111n : 511n
const tenBit = 0b1111111111n; // 1023n
>tenBit : 1023n
>0b1111111111n : 1023n
const elevenBit = 0b11111111111n; // 2047n
>elevenBit : 2047n
>0b11111111111n : 2047n
const twelveBit = 0b111111111111n; // 4095n
>twelveBit : 4095n
>0b111111111111n : 4095n
const thirteenBit = 0b1111111111111n; // 8191n
>thirteenBit : 8191n
>0b1111111111111n : 8191n
const fourteenBit = 0b11111111111111n; // 16383n
>fourteenBit : 16383n
>0b11111111111111n : 16383n
const fifteenBit = 0b111111111111111n; // 32767n
>fifteenBit : 32767n
>0b111111111111111n : 32767n
const sixteenBit = 0b1111111111111111n; // 65535n
>sixteenBit : 65535n
>0b1111111111111111n : 65535n
const seventeenBit = 0b11111111111111111n; // 131071n
>seventeenBit : 131071n
>0b11111111111111111n : 131071n
// Test negative literals
const neg = -123n;
>neg : -123n
>-123n : -123n
>123n : 123n
const negHex: -16n = -0x10n;
>negHex : -16n
>-16n : -16n
>16n : 16n
>-0x10n : -16n
>0x10n : 16n
// Test normalization of bigints -- all of these should succeed
const negZero: 0n = -0n;
>negZero : 0n
>-0n : 0n
>0n : 0n
const baseChange: 255n = 0xFFn;
>baseChange : 255n
>0xFFn : 255n
const leadingZeros: 0xFFn = 0x000000FFn;
>leadingZeros : 255n
>0x000000FFn : 255n
// Plus not allowed on literals
const unaryPlus = +123n;
>unaryPlus : 123n
>+123n : 123n
>123n : 123n
const unaryPlusHex = +0x123n;
>unaryPlusHex : 291n
>+0x123n : 291n
>0x123n : 291n
// Parsing errors
// In separate blocks because they each declare an "n" variable
{ const legacyOct = 0123n; }
>legacyOct : 123
>0123 : 123
>n : any
{ const scientific = 1e2n; }
>scientific : 100
>1e2 : 100
>n : any
{ const decimal = 4.1n; }
>decimal : 4.1
>4.1 : 4.1
>n : any
{ const leadingDecimal = .1n; }
>leadingDecimal : 0.1
>.1 : 0.1
>n : any
const emptyBinary = 0bn; // should error but infer 0n
>emptyBinary : 0n
>0bn : 0n
const emptyOct = 0on; // should error but infer 0n
>emptyOct : 0n
>0on : 0n
const emptyHex = 0xn; // should error but infer 0n
>emptyHex : 0n
>0xn : 0n
const leadingSeparator = _123n;
>leadingSeparator : any
>_123n : any
const trailingSeparator = 123_n;
>trailingSeparator : 123n
>123_n : 123n
const doubleSeparator = 123_456__789n;
>doubleSeparator : 123456789n
>123_456__789n : 123456789n
// Using literals as types
const oneTwoOrThree = (x: 1n | 2n | 3n): bigint => x ** 2n;
>oneTwoOrThree : (x: 1n | 3n | 2n) => bigint
>(x: 1n | 2n | 3n): bigint => x ** 2n : (x: 1n | 3n | 2n) => bigint
>x : 1n | 3n | 2n
>x ** 2n : bigint
>x : 1n | 3n | 2n
>2n : 2n
oneTwoOrThree(0n); oneTwoOrThree(1n); oneTwoOrThree(2n); oneTwoOrThree(3n);
>oneTwoOrThree(0n) : bigint
>oneTwoOrThree : (x: 1n | 3n | 2n) => bigint
>0n : 0n
>oneTwoOrThree(1n) : bigint
>oneTwoOrThree : (x: 1n | 3n | 2n) => bigint
>1n : 1n
>oneTwoOrThree(2n) : bigint
>oneTwoOrThree : (x: 1n | 3n | 2n) => bigint
>2n : 2n
>oneTwoOrThree(3n) : bigint
>oneTwoOrThree : (x: 1n | 3n | 2n) => bigint
>3n : 3n
oneTwoOrThree(0); oneTwoOrThree(1); oneTwoOrThree(2); oneTwoOrThree(3);
>oneTwoOrThree(0) : bigint
>oneTwoOrThree : (x: 1n | 3n | 2n) => bigint
>0 : 0
>oneTwoOrThree(1) : bigint
>oneTwoOrThree : (x: 1n | 3n | 2n) => bigint
>1 : 1
>oneTwoOrThree(2) : bigint
>oneTwoOrThree : (x: 1n | 3n | 2n) => bigint
>2 : 2
>oneTwoOrThree(3) : bigint
>oneTwoOrThree : (x: 1n | 3n | 2n) => bigint
>3 : 3

View File

@@ -1,17 +1,22 @@
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(2,22): error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(2,29): error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(2,39): error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(2,48): error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(3,24): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(4,22): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(4,29): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(4,39): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(4,48): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
==== tests/cases/compiler/warnExperimentalBigIntLiteral.ts (4 errors) ====
==== tests/cases/compiler/warnExperimentalBigIntLiteral.ts (5 errors) ====
const normalNumber = 123; // should not error
let bigintType: bigint; // should not error
let bigintLiteralType: 123n; // should error when used as type
~~~~
!!! error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
~~~~
!!! error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
!!! error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
~~~~~~~
!!! error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
!!! error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
~~~~~~
!!! error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
!!! error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
~~~~~
!!! error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
!!! error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.

View File

@@ -1,7 +1,11 @@
//// [warnExperimentalBigIntLiteral.ts]
const normalNumber = 123; // should not error
let bigintType: bigint; // should not error
let bigintLiteralType: 123n; // should error when used as type
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
//// [warnExperimentalBigIntLiteral.js]
var normalNumber = 123; // should not error
var bigintType; // should not error
var bigintLiteralType; // should error when used as type
var bigintNumber = 123n * 15n + 292n * 0x7fn; // each literal should error

View File

@@ -2,6 +2,12 @@
const normalNumber = 123; // should not error
>normalNumber : Symbol(normalNumber, Decl(warnExperimentalBigIntLiteral.ts, 0, 5))
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
>bigintNumber : Symbol(bigintNumber, Decl(warnExperimentalBigIntLiteral.ts, 1, 5))
let bigintType: bigint; // should not error
>bigintType : Symbol(bigintType, Decl(warnExperimentalBigIntLiteral.ts, 1, 3))
let bigintLiteralType: 123n; // should error when used as type
>bigintLiteralType : Symbol(bigintLiteralType, Decl(warnExperimentalBigIntLiteral.ts, 2, 3))
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
>bigintNumber : Symbol(bigintNumber, Decl(warnExperimentalBigIntLiteral.ts, 3, 5))

View File

@@ -3,6 +3,12 @@ const normalNumber = 123; // should not error
>normalNumber : 123
>123 : 123
let bigintType: bigint; // should not error
>bigintType : bigint
let bigintLiteralType: 123n; // should error when used as type
>bigintLiteralType : 123n
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
>bigintNumber : bigint
>123n * 0b1111n + 0o444n * 0x7fn : bigint

View File

@@ -0,0 +1,25 @@
// @target: es2015
// @experimentalBigInt: true
interface BigIntIndex<E> {
[index: bigint]: E; // should error
}
const arr: number[] = [1, 2, 3];
let num: number = arr[1];
num = arr["1"];
num = arr[1n]; // should error
let key: keyof any; // should be type "string | number | symbol"
key = 123;
key = "abc";
key = Symbol();
key = 123n; // should error
// Show correct usage of bigint index: explicitly convert to string
const bigNum: bigint = 0n;
const typedArray = new Uint8Array(3);
typedArray[bigNum] = 0xAA; // should error
typedArray[String(bigNum)] = 0xAA;
typedArray["1"] = 0xBB;
typedArray[2] = 0xCC;

View File

@@ -0,0 +1,50 @@
// @experimentalBigInt: true
// @target: esnext
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
bigintVal = BigInt("456");
new BigInt(123); // should error
bigintVal = BigInt.asIntN(8, 0xFFFFn);
bigintVal = BigInt.asUintN(8, 0xFFFFn);
bigintVal = bigintVal.valueOf();
let stringVal: string = bigintVal.toString();
stringVal = bigintVal.toString(2);
stringVal = bigintVal.toLocaleString();
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
bigIntArray = new BigInt64Array(10);
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
bigIntArray = new BigInt64Array([1, 2, 3]); // should error
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
let len: number = bigIntArray.length;
bigIntArray.length = 10; // should error
let arrayBufferLike: ArrayBufferView = bigIntArray;
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
bigUintArray = new BigUint64Array(10);
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
bigUintArray = new BigUint64Array([1, 2, 3]); // should error
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
len = bigIntArray.length;
bigIntArray.length = 10; // should error
arrayBufferLike = bigIntArray;
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
dataView.setBigInt64(1, -1n);
dataView.setBigInt64(1, -1n, true);
dataView.setBigInt64(1, -1); // should error
dataView.setBigUint64(2, 123n);
dataView.setBigUint64(2, 123n, true);
dataView.setBigUint64(2, 123); // should error
bigintVal = dataView.getBigInt64(1);
bigintVal = dataView.getBigInt64(1, true);
bigintVal = dataView.getBigUint64(2);
bigintVal = dataView.getBigUint64(2, true);

View File

@@ -0,0 +1,52 @@
// @experimentalBigInt: true
// @target: es5
// Every line should error because these builtins are not declared
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
bigintVal = BigInt("456");
new BigInt(123);
bigintVal = BigInt.asIntN(8, 0xFFFFn);
bigintVal = BigInt.asUintN(8, 0xFFFFn);
bigintVal = bigintVal.valueOf(); // should error - bigintVal inferred as {}
let stringVal: string = bigintVal.toString(); // should not error - bigintVal inferred as {}
stringVal = bigintVal.toString(2); // should error - bigintVal inferred as {}
stringVal = bigintVal.toLocaleString(); // should not error - bigintVal inferred as {}
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
bigIntArray = new BigInt64Array(10);
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
bigIntArray = new BigInt64Array([1, 2, 3]);
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
let len: number = bigIntArray.length;
bigIntArray.length = 10;
let arrayBufferLike: ArrayBufferView = bigIntArray;
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
bigUintArray = new BigUint64Array(10);
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
bigUintArray = new BigUint64Array([1, 2, 3]);
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
len = bigIntArray.length;
bigIntArray.length = 10;
arrayBufferLike = bigIntArray;
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
dataView.setBigInt64(1, -1n);
dataView.setBigInt64(1, -1n, true);
dataView.setBigInt64(1, -1);
dataView.setBigUint64(2, 123n);
dataView.setBigUint64(2, 123n, true);
dataView.setBigUint64(2, 123);
bigintVal = dataView.getBigInt64(1);
bigintVal = dataView.getBigInt64(1, true);
bigintVal = dataView.getBigUint64(2);
bigintVal = dataView.getBigUint64(2, true);

View File

@@ -0,0 +1,96 @@
// @experimentalBigInt: true
// Cannot mix bigints and numbers
let bigInt = 1n, num = 2;
bigInt = 1n; bigInt = 2; num = 1n; num = 2;
bigInt += 1n; bigInt += 2; num += 1n; num += 2;
bigInt -= 1n; bigInt -= 2; num -= 1n; num -= 2;
bigInt *= 1n; bigInt *= 2; num *= 1n; num *= 2;
bigInt /= 1n; bigInt /= 2; num /= 1n; num /= 2;
bigInt %= 1n; bigInt %= 2; num %= 1n; num %= 2;
bigInt **= 1n; bigInt **= 2; num **= 1n; num **= 2;
bigInt <<= 1n; bigInt <<= 2; num <<= 1n; num <<= 2;
bigInt >>= 1n; bigInt >>= 2; num >>= 1n; num >>= 2;
bigInt &= 1n; bigInt &= 2; num &= 1n; num &= 2;
bigInt ^= 1n; bigInt ^= 2; num ^= 1n; num ^= 2;
bigInt |= 1n; bigInt |= 2; num |= 1n; num |= 2;
bigInt = 1n + 2n; num = 1 + 2; 1 + 2n; 1n + 2;
bigInt = 1n - 2n; num = 1 - 2; 1 - 2n; 1n - 2;
bigInt = 1n * 2n; num = 1 * 2; 1 * 2n; 1n * 2;
bigInt = 1n / 2n; num = 1 / 2; 1 / 2n; 1n / 2;
bigInt = 1n % 2n; num = 1 % 2; 1 % 2n; 1n % 2;
bigInt = 1n ** 2n; num = 1 ** 2; 1 ** 2n; 1n ** 2;
bigInt = 1n & 2n; num = 1 & 2; 1 & 2n; 1n & 2;
bigInt = 1n | 2n; num = 1 | 2; 1 | 2n; 1n | 2;
bigInt = 1n ^ 2n; num = 1 ^ 2; 1 ^ 2n; 1n ^ 2;
bigInt = 1n << 2n; num = 1 << 2; 1 << 2n; 1n << 2;
bigInt = 1n >> 2n; num = 1 >> 2; 1 >> 2n; 1n >> 2;
// Plus should still coerce to strings
let str: string;
str = "abc" + 123; str = "abc" + 123n; str = 123 + "abc"; str = 123n + "abc";
// Unary operations allowed on bigints and numbers
bigInt = bigInt++; bigInt = ++bigInt; num = num++; num = ++num;
bigInt = bigInt--; bigInt = --bigInt; num = num--; num = --num;
bigInt = -bigInt; num = -num;
bigInt = ~bigInt; num = ~num;
// Number-only operations
bigInt >>>= 1n; num >>>= 2;
bigInt = bigInt >>> 1n; num = num >>> 2;
num = +bigInt; num = +num; num = +"3";
// Comparisons can be mixed
let result: boolean;
result = bigInt > num;
result = bigInt >= num;
result = bigInt < num;
result = bigInt <= num;
// Trying to compare for equality is likely an error (since 1 == "1" is disallowed)
result = bigInt == num;
result = bigInt != num;
result = bigInt === num;
result = bigInt !== num;
// Types of arithmetic operations on other types
num = "3" & 5; num = 2 ** false; // should error, but infer number
"3" & 5n; 2n ** false; // should error, result in any
num = ~"3"; num = -false; // should infer number
let bigIntOrNumber: bigint | number;
bigIntOrNumber + bigIntOrNumber; // should error, result in any
bigIntOrNumber << bigIntOrNumber; // should error, result in any
if (typeof bigIntOrNumber === "bigint") {
// Allowed, as type is narrowed to bigint
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
}
if (typeof bigIntOrNumber === "number") {
// Allowed, as type is narrowed to number
bigIntOrNumber = bigIntOrNumber << bigIntOrNumber;
}
+bigIntOrNumber; // should error, result in number
~bigIntOrNumber; // should infer number | bigint
bigIntOrNumber++; // should infer number | bigint
++bigIntOrNumber; // should infer number | bigint
let anyValue: any;
anyValue + anyValue; // should infer any
anyValue >>> anyValue; // should infer number
anyValue ^ anyValue; // should infer number
+anyValue; // should infer number
-anyValue; // should infer number
anyValue--; // should infer number
--anyValue; // should infer number
// Distinguishing numbers from bigints with typeof
const isBigInt: (x: 0n | 1n) => bigint = (x: 0n | 1n) => x;
const isNumber: (x: 0 | 1) => number = (x: 0 | 1) => x;
const zeroOrBigOne: 0 | 1n;
if (typeof zeroOrBigOne === "bigint") isBigInt(zeroOrBigOne);
else isNumber(zeroOrBigOne);
// Distinguishing truthy from falsy
const isOne = (x: 1 | 1n) => x;
if (zeroOrBigOne) isOne(zeroOrBigOne);
const bigZeroOrOne: 0n | 1;
if (bigZeroOrOne) isOne(bigZeroOrOne);

View File

@@ -0,0 +1,72 @@
// @experimentalBigInt: true
// All bases should allow "n" suffix
const bin = 0b101, binBig = 0b101n; // 5, 5n
const oct = 0o567, octBig = 0o567n; // 375, 375n
const hex = 0xC0B, hexBig = 0xC0Bn; // 3083, 3083n
const dec = 123, decBig = 123n;
// Test literals whose values overflow a 53-bit integer
// These should be represented exactly in the emitted JS
const largeBin = 0b10101010101010101010101010101010101010101010101010101010101n; // 384307168202282325n
const largeOct = 0o123456712345671234567n; // 1505852261029722487n
const largeDec = 12345678091234567890n;
const largeHex = 0x1234567890abcdefn; // 1311768467294899695n
// Test literals with separators
const separatedBin = 0b010_10_1n; // 21n
const separatedOct = 0o1234_567n; // 342391n
const separatedDec = 123_456_789n;
const separatedHex = 0x0_abcdefn; // 11259375n
// Test parsing literals of different bit sizes
// to ensure that parsePseudoBigInt() allocates enough space
const zero = 0b0n;
const oneBit = 0b1n;
const twoBit = 0b11n; // 3n
const threeBit = 0b111n; // 7n
const fourBit = 0b1111n; // 15n
const fiveBit = 0b11111n; // 31n
const sixBit = 0b111111n; // 63n
const sevenBit = 0b1111111n; // 127n
const eightBit = 0b11111111n; // 255n
const nineBit = 0b111111111n; // 511n
const tenBit = 0b1111111111n; // 1023n
const elevenBit = 0b11111111111n; // 2047n
const twelveBit = 0b111111111111n; // 4095n
const thirteenBit = 0b1111111111111n; // 8191n
const fourteenBit = 0b11111111111111n; // 16383n
const fifteenBit = 0b111111111111111n; // 32767n
const sixteenBit = 0b1111111111111111n; // 65535n
const seventeenBit = 0b11111111111111111n; // 131071n
// Test negative literals
const neg = -123n;
const negHex: -16n = -0x10n;
// Test normalization of bigints -- all of these should succeed
const negZero: 0n = -0n;
const baseChange: 255n = 0xFFn;
const leadingZeros: 0xFFn = 0x000000FFn;
// Plus not allowed on literals
const unaryPlus = +123n;
const unaryPlusHex = +0x123n;
// Parsing errors
// In separate blocks because they each declare an "n" variable
{ const legacyOct = 0123n; }
{ const scientific = 1e2n; }
{ const decimal = 4.1n; }
{ const leadingDecimal = .1n; }
const emptyBinary = 0bn; // should error but infer 0n
const emptyOct = 0on; // should error but infer 0n
const emptyHex = 0xn; // should error but infer 0n
const leadingSeparator = _123n;
const trailingSeparator = 123_n;
const doubleSeparator = 123_456__789n;
// Using literals as types
const oneTwoOrThree = (x: 1n | 2n | 3n): bigint => x ** 2n;
oneTwoOrThree(0n); oneTwoOrThree(1n); oneTwoOrThree(2n); oneTwoOrThree(3n);
oneTwoOrThree(0); oneTwoOrThree(1); oneTwoOrThree(2); oneTwoOrThree(3);

View File

@@ -1,2 +1,4 @@
const normalNumber = 123; // should not error
let bigintType: bigint; // should not error
let bigintLiteralType: 123n; // should error when used as type
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error