mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Add valueOf declarations for TypedArrays (#36668)
This commit is contained in:
parent
4c160683c3
commit
4432178ded
6
src/lib/es2020.bigint.d.ts
vendored
6
src/lib/es2020.bigint.d.ts
vendored
@ -268,6 +268,9 @@ interface BigInt64Array {
|
||||
/** Returns a string representation of the array. */
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): BigInt64Array;
|
||||
|
||||
/** Yields each value in the array. */
|
||||
values(): IterableIterator<bigint>;
|
||||
|
||||
@ -537,6 +540,9 @@ interface BigUint64Array {
|
||||
/** Returns a string representation of the array. */
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): BigUint64Array;
|
||||
|
||||
/** Yields each value in the array. */
|
||||
values(): IterableIterator<bigint>;
|
||||
|
||||
|
||||
27
src/lib/es5.d.ts
vendored
27
src/lib/es5.d.ts
vendored
@ -1920,6 +1920,9 @@ interface Int8Array {
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): Int8Array;
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
interface Int8ArrayConstructor {
|
||||
@ -2199,6 +2202,9 @@ interface Uint8Array {
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): Uint8Array;
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
|
||||
@ -2478,6 +2484,9 @@ interface Uint8ClampedArray {
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): Uint8ClampedArray;
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
|
||||
@ -2755,6 +2764,9 @@ interface Int16Array {
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): Int16Array;
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
|
||||
@ -3035,6 +3047,9 @@ interface Uint16Array {
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): Uint16Array;
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
|
||||
@ -3314,6 +3329,9 @@ interface Int32Array {
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): Int32Array;
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
|
||||
@ -3592,6 +3610,9 @@ interface Uint32Array {
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): Uint32Array;
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
|
||||
@ -3871,6 +3892,9 @@ interface Float32Array {
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): Float32Array;
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
|
||||
@ -4142,6 +4166,9 @@ interface Float64Array {
|
||||
|
||||
toString(): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): Float64Array;
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
|
||||
|
||||
26
tests/baselines/reference/valueOfTypedArray.js
Normal file
26
tests/baselines/reference/valueOfTypedArray.js
Normal file
@ -0,0 +1,26 @@
|
||||
//// [valueOfTypedArray.ts]
|
||||
// All declarations should pass, as valueOf has been specialized for all TypedArrays
|
||||
const typedArray0: Int8Array = (new Int8Array()).valueOf();
|
||||
const typedArray1: Uint8Array = (new Uint8Array()).valueOf();
|
||||
const typedArray2: Int16Array = (new Int16Array()).valueOf();
|
||||
const typedArray3: Uint16Array = (new Uint16Array()).valueOf();
|
||||
const typedArray4: Int32Array = (new Int32Array()).valueOf();
|
||||
const typedArray5: Uint32Array = (new Uint32Array()).valueOf();
|
||||
const typedArray6: Float32Array = (new Float32Array()).valueOf();
|
||||
const typedArray7: Float64Array = (new Float64Array()).valueOf();
|
||||
const typedArray8: BigInt64Array = (new BigInt64Array()).valueOf();
|
||||
const typedArray9: BigUint64Array = (new BigUint64Array()).valueOf();
|
||||
|
||||
|
||||
//// [valueOfTypedArray.js]
|
||||
// All declarations should pass, as valueOf has been specialized for all TypedArrays
|
||||
const typedArray0 = (new Int8Array()).valueOf();
|
||||
const typedArray1 = (new Uint8Array()).valueOf();
|
||||
const typedArray2 = (new Int16Array()).valueOf();
|
||||
const typedArray3 = (new Uint16Array()).valueOf();
|
||||
const typedArray4 = (new Int32Array()).valueOf();
|
||||
const typedArray5 = (new Uint32Array()).valueOf();
|
||||
const typedArray6 = (new Float32Array()).valueOf();
|
||||
const typedArray7 = (new Float64Array()).valueOf();
|
||||
const typedArray8 = (new BigInt64Array()).valueOf();
|
||||
const typedArray9 = (new BigUint64Array()).valueOf();
|
||||
72
tests/baselines/reference/valueOfTypedArray.symbols
Normal file
72
tests/baselines/reference/valueOfTypedArray.symbols
Normal file
@ -0,0 +1,72 @@
|
||||
=== tests/cases/compiler/valueOfTypedArray.ts ===
|
||||
// All declarations should pass, as valueOf has been specialized for all TypedArrays
|
||||
const typedArray0: Int8Array = (new Int8Array()).valueOf();
|
||||
>typedArray0 : Symbol(typedArray0, Decl(valueOfTypedArray.ts, 1, 5))
|
||||
>Int8Array : Symbol(Int8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>(new Int8Array()).valueOf : Symbol(Int8Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
>Int8Array : Symbol(Int8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>valueOf : Symbol(Int8Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
const typedArray1: Uint8Array = (new Uint8Array()).valueOf();
|
||||
>typedArray1 : Symbol(typedArray1, Decl(valueOfTypedArray.ts, 2, 5))
|
||||
>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>(new Uint8Array()).valueOf : Symbol(Uint8Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>valueOf : Symbol(Uint8Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
const typedArray2: Int16Array = (new Int16Array()).valueOf();
|
||||
>typedArray2 : Symbol(typedArray2, Decl(valueOfTypedArray.ts, 3, 5))
|
||||
>Int16Array : Symbol(Int16Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>(new Int16Array()).valueOf : Symbol(Int16Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
>Int16Array : Symbol(Int16Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>valueOf : Symbol(Int16Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
const typedArray3: Uint16Array = (new Uint16Array()).valueOf();
|
||||
>typedArray3 : Symbol(typedArray3, Decl(valueOfTypedArray.ts, 4, 5))
|
||||
>Uint16Array : Symbol(Uint16Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>(new Uint16Array()).valueOf : Symbol(Uint16Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
>Uint16Array : Symbol(Uint16Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>valueOf : Symbol(Uint16Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
const typedArray4: Int32Array = (new Int32Array()).valueOf();
|
||||
>typedArray4 : Symbol(typedArray4, Decl(valueOfTypedArray.ts, 5, 5))
|
||||
>Int32Array : Symbol(Int32Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>(new Int32Array()).valueOf : Symbol(Int32Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
>Int32Array : Symbol(Int32Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>valueOf : Symbol(Int32Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
const typedArray5: Uint32Array = (new Uint32Array()).valueOf();
|
||||
>typedArray5 : Symbol(typedArray5, Decl(valueOfTypedArray.ts, 6, 5))
|
||||
>Uint32Array : Symbol(Uint32Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>(new Uint32Array()).valueOf : Symbol(Uint32Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
>Uint32Array : Symbol(Uint32Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>valueOf : Symbol(Uint32Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
const typedArray6: Float32Array = (new Float32Array()).valueOf();
|
||||
>typedArray6 : Symbol(typedArray6, Decl(valueOfTypedArray.ts, 7, 5))
|
||||
>Float32Array : Symbol(Float32Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>(new Float32Array()).valueOf : Symbol(Float32Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
>Float32Array : Symbol(Float32Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>valueOf : Symbol(Float32Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
const typedArray7: Float64Array = (new Float64Array()).valueOf();
|
||||
>typedArray7 : Symbol(typedArray7, Decl(valueOfTypedArray.ts, 8, 5))
|
||||
>Float64Array : Symbol(Float64Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>(new Float64Array()).valueOf : Symbol(Float64Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
>Float64Array : Symbol(Float64Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --))
|
||||
>valueOf : Symbol(Float64Array.valueOf, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
const typedArray8: BigInt64Array = (new BigInt64Array()).valueOf();
|
||||
>typedArray8 : Symbol(typedArray8, Decl(valueOfTypedArray.ts, 9, 5))
|
||||
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
|
||||
>(new BigInt64Array()).valueOf : Symbol(BigInt64Array.valueOf, Decl(lib.es2020.bigint.d.ts, --, --))
|
||||
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
|
||||
>valueOf : Symbol(BigInt64Array.valueOf, Decl(lib.es2020.bigint.d.ts, --, --))
|
||||
|
||||
const typedArray9: BigUint64Array = (new BigUint64Array()).valueOf();
|
||||
>typedArray9 : Symbol(typedArray9, Decl(valueOfTypedArray.ts, 10, 5))
|
||||
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
|
||||
>(new BigUint64Array()).valueOf : Symbol(BigUint64Array.valueOf, Decl(lib.es2020.bigint.d.ts, --, --))
|
||||
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
|
||||
>valueOf : Symbol(BigUint64Array.valueOf, Decl(lib.es2020.bigint.d.ts, --, --))
|
||||
|
||||
92
tests/baselines/reference/valueOfTypedArray.types
Normal file
92
tests/baselines/reference/valueOfTypedArray.types
Normal file
@ -0,0 +1,92 @@
|
||||
=== tests/cases/compiler/valueOfTypedArray.ts ===
|
||||
// All declarations should pass, as valueOf has been specialized for all TypedArrays
|
||||
const typedArray0: Int8Array = (new Int8Array()).valueOf();
|
||||
>typedArray0 : Int8Array
|
||||
>(new Int8Array()).valueOf() : Int8Array
|
||||
>(new Int8Array()).valueOf : () => Int8Array
|
||||
>(new Int8Array()) : Int8Array
|
||||
>new Int8Array() : Int8Array
|
||||
>Int8Array : Int8ArrayConstructor
|
||||
>valueOf : () => Int8Array
|
||||
|
||||
const typedArray1: Uint8Array = (new Uint8Array()).valueOf();
|
||||
>typedArray1 : Uint8Array
|
||||
>(new Uint8Array()).valueOf() : Uint8Array
|
||||
>(new Uint8Array()).valueOf : () => Uint8Array
|
||||
>(new Uint8Array()) : Uint8Array
|
||||
>new Uint8Array() : Uint8Array
|
||||
>Uint8Array : Uint8ArrayConstructor
|
||||
>valueOf : () => Uint8Array
|
||||
|
||||
const typedArray2: Int16Array = (new Int16Array()).valueOf();
|
||||
>typedArray2 : Int16Array
|
||||
>(new Int16Array()).valueOf() : Int16Array
|
||||
>(new Int16Array()).valueOf : () => Int16Array
|
||||
>(new Int16Array()) : Int16Array
|
||||
>new Int16Array() : Int16Array
|
||||
>Int16Array : Int16ArrayConstructor
|
||||
>valueOf : () => Int16Array
|
||||
|
||||
const typedArray3: Uint16Array = (new Uint16Array()).valueOf();
|
||||
>typedArray3 : Uint16Array
|
||||
>(new Uint16Array()).valueOf() : Uint16Array
|
||||
>(new Uint16Array()).valueOf : () => Uint16Array
|
||||
>(new Uint16Array()) : Uint16Array
|
||||
>new Uint16Array() : Uint16Array
|
||||
>Uint16Array : Uint16ArrayConstructor
|
||||
>valueOf : () => Uint16Array
|
||||
|
||||
const typedArray4: Int32Array = (new Int32Array()).valueOf();
|
||||
>typedArray4 : Int32Array
|
||||
>(new Int32Array()).valueOf() : Int32Array
|
||||
>(new Int32Array()).valueOf : () => Int32Array
|
||||
>(new Int32Array()) : Int32Array
|
||||
>new Int32Array() : Int32Array
|
||||
>Int32Array : Int32ArrayConstructor
|
||||
>valueOf : () => Int32Array
|
||||
|
||||
const typedArray5: Uint32Array = (new Uint32Array()).valueOf();
|
||||
>typedArray5 : Uint32Array
|
||||
>(new Uint32Array()).valueOf() : Uint32Array
|
||||
>(new Uint32Array()).valueOf : () => Uint32Array
|
||||
>(new Uint32Array()) : Uint32Array
|
||||
>new Uint32Array() : Uint32Array
|
||||
>Uint32Array : Uint32ArrayConstructor
|
||||
>valueOf : () => Uint32Array
|
||||
|
||||
const typedArray6: Float32Array = (new Float32Array()).valueOf();
|
||||
>typedArray6 : Float32Array
|
||||
>(new Float32Array()).valueOf() : Float32Array
|
||||
>(new Float32Array()).valueOf : () => Float32Array
|
||||
>(new Float32Array()) : Float32Array
|
||||
>new Float32Array() : Float32Array
|
||||
>Float32Array : Float32ArrayConstructor
|
||||
>valueOf : () => Float32Array
|
||||
|
||||
const typedArray7: Float64Array = (new Float64Array()).valueOf();
|
||||
>typedArray7 : Float64Array
|
||||
>(new Float64Array()).valueOf() : Float64Array
|
||||
>(new Float64Array()).valueOf : () => Float64Array
|
||||
>(new Float64Array()) : Float64Array
|
||||
>new Float64Array() : Float64Array
|
||||
>Float64Array : Float64ArrayConstructor
|
||||
>valueOf : () => Float64Array
|
||||
|
||||
const typedArray8: BigInt64Array = (new BigInt64Array()).valueOf();
|
||||
>typedArray8 : BigInt64Array
|
||||
>(new BigInt64Array()).valueOf() : BigInt64Array
|
||||
>(new BigInt64Array()).valueOf : () => BigInt64Array
|
||||
>(new BigInt64Array()) : BigInt64Array
|
||||
>new BigInt64Array() : BigInt64Array
|
||||
>BigInt64Array : BigInt64ArrayConstructor
|
||||
>valueOf : () => BigInt64Array
|
||||
|
||||
const typedArray9: BigUint64Array = (new BigUint64Array()).valueOf();
|
||||
>typedArray9 : BigUint64Array
|
||||
>(new BigUint64Array()).valueOf() : BigUint64Array
|
||||
>(new BigUint64Array()).valueOf : () => BigUint64Array
|
||||
>(new BigUint64Array()) : BigUint64Array
|
||||
>new BigUint64Array() : BigUint64Array
|
||||
>BigUint64Array : BigUint64ArrayConstructor
|
||||
>valueOf : () => BigUint64Array
|
||||
|
||||
13
tests/cases/compiler/valueOfTypedArray.ts
Normal file
13
tests/cases/compiler/valueOfTypedArray.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// @target: es2020
|
||||
|
||||
// All declarations should pass, as valueOf has been specialized for all TypedArrays
|
||||
const typedArray0: Int8Array = (new Int8Array()).valueOf();
|
||||
const typedArray1: Uint8Array = (new Uint8Array()).valueOf();
|
||||
const typedArray2: Int16Array = (new Int16Array()).valueOf();
|
||||
const typedArray3: Uint16Array = (new Uint16Array()).valueOf();
|
||||
const typedArray4: Int32Array = (new Int32Array()).valueOf();
|
||||
const typedArray5: Uint32Array = (new Uint32Array()).valueOf();
|
||||
const typedArray6: Float32Array = (new Float32Array()).valueOf();
|
||||
const typedArray7: Float64Array = (new Float64Array()).valueOf();
|
||||
const typedArray8: BigInt64Array = (new BigInt64Array()).valueOf();
|
||||
const typedArray9: BigUint64Array = (new BigUint64Array()).valueOf();
|
||||
Loading…
x
Reference in New Issue
Block a user