Skip to content

Commit 4432178

Browse files
authored
Add valueOf declarations for TypedArrays (microsoft#36668)
1 parent 4c16068 commit 4432178

6 files changed

Lines changed: 236 additions & 0 deletions

File tree

src/lib/es2020.bigint.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ interface BigInt64Array {
268268
/** Returns a string representation of the array. */
269269
toString(): string;
270270

271+
/** Returns the primitive value of the specified object. */
272+
valueOf(): BigInt64Array;
273+
271274
/** Yields each value in the array. */
272275
values(): IterableIterator<bigint>;
273276

@@ -537,6 +540,9 @@ interface BigUint64Array {
537540
/** Returns a string representation of the array. */
538541
toString(): string;
539542

543+
/** Returns the primitive value of the specified object. */
544+
valueOf(): BigUint64Array;
545+
540546
/** Yields each value in the array. */
541547
values(): IterableIterator<bigint>;
542548

src/lib/es5.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,9 @@ interface Int8Array {
19201920
*/
19211921
toString(): string;
19221922

1923+
/** Returns the primitive value of the specified object. */
1924+
valueOf(): Int8Array;
1925+
19231926
[index: number]: number;
19241927
}
19251928
interface Int8ArrayConstructor {
@@ -2199,6 +2202,9 @@ interface Uint8Array {
21992202
*/
22002203
toString(): string;
22012204

2205+
/** Returns the primitive value of the specified object. */
2206+
valueOf(): Uint8Array;
2207+
22022208
[index: number]: number;
22032209
}
22042210

@@ -2478,6 +2484,9 @@ interface Uint8ClampedArray {
24782484
*/
24792485
toString(): string;
24802486

2487+
/** Returns the primitive value of the specified object. */
2488+
valueOf(): Uint8ClampedArray;
2489+
24812490
[index: number]: number;
24822491
}
24832492

@@ -2755,6 +2764,9 @@ interface Int16Array {
27552764
*/
27562765
toString(): string;
27572766

2767+
/** Returns the primitive value of the specified object. */
2768+
valueOf(): Int16Array;
2769+
27582770
[index: number]: number;
27592771
}
27602772

@@ -3035,6 +3047,9 @@ interface Uint16Array {
30353047
*/
30363048
toString(): string;
30373049

3050+
/** Returns the primitive value of the specified object. */
3051+
valueOf(): Uint16Array;
3052+
30383053
[index: number]: number;
30393054
}
30403055

@@ -3314,6 +3329,9 @@ interface Int32Array {
33143329
*/
33153330
toString(): string;
33163331

3332+
/** Returns the primitive value of the specified object. */
3333+
valueOf(): Int32Array;
3334+
33173335
[index: number]: number;
33183336
}
33193337

@@ -3592,6 +3610,9 @@ interface Uint32Array {
35923610
*/
35933611
toString(): string;
35943612

3613+
/** Returns the primitive value of the specified object. */
3614+
valueOf(): Uint32Array;
3615+
35953616
[index: number]: number;
35963617
}
35973618

@@ -3871,6 +3892,9 @@ interface Float32Array {
38713892
*/
38723893
toString(): string;
38733894

3895+
/** Returns the primitive value of the specified object. */
3896+
valueOf(): Float32Array;
3897+
38743898
[index: number]: number;
38753899
}
38763900

@@ -4142,6 +4166,9 @@ interface Float64Array {
41424166

41434167
toString(): string;
41444168

4169+
/** Returns the primitive value of the specified object. */
4170+
valueOf(): Float64Array;
4171+
41454172
[index: number]: number;
41464173
}
41474174

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [valueOfTypedArray.ts]
2+
// All declarations should pass, as valueOf has been specialized for all TypedArrays
3+
const typedArray0: Int8Array = (new Int8Array()).valueOf();
4+
const typedArray1: Uint8Array = (new Uint8Array()).valueOf();
5+
const typedArray2: Int16Array = (new Int16Array()).valueOf();
6+
const typedArray3: Uint16Array = (new Uint16Array()).valueOf();
7+
const typedArray4: Int32Array = (new Int32Array()).valueOf();
8+
const typedArray5: Uint32Array = (new Uint32Array()).valueOf();
9+
const typedArray6: Float32Array = (new Float32Array()).valueOf();
10+
const typedArray7: Float64Array = (new Float64Array()).valueOf();
11+
const typedArray8: BigInt64Array = (new BigInt64Array()).valueOf();
12+
const typedArray9: BigUint64Array = (new BigUint64Array()).valueOf();
13+
14+
15+
//// [valueOfTypedArray.js]
16+
// All declarations should pass, as valueOf has been specialized for all TypedArrays
17+
const typedArray0 = (new Int8Array()).valueOf();
18+
const typedArray1 = (new Uint8Array()).valueOf();
19+
const typedArray2 = (new Int16Array()).valueOf();
20+
const typedArray3 = (new Uint16Array()).valueOf();
21+
const typedArray4 = (new Int32Array()).valueOf();
22+
const typedArray5 = (new Uint32Array()).valueOf();
23+
const typedArray6 = (new Float32Array()).valueOf();
24+
const typedArray7 = (new Float64Array()).valueOf();
25+
const typedArray8 = (new BigInt64Array()).valueOf();
26+
const typedArray9 = (new BigUint64Array()).valueOf();
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
=== tests/cases/compiler/valueOfTypedArray.ts ===
2+
// All declarations should pass, as valueOf has been specialized for all TypedArrays
3+
const typedArray0: Int8Array = (new Int8Array()).valueOf();
4+
>typedArray0 : Symbol(typedArray0, Decl(valueOfTypedArray.ts, 1, 5))
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, --, --))
6+
>(new Int8Array()).valueOf : Symbol(Int8Array.valueOf, Decl(lib.es5.d.ts, --, --))
7+
>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, --, --))
8+
>valueOf : Symbol(Int8Array.valueOf, Decl(lib.es5.d.ts, --, --))
9+
10+
const typedArray1: Uint8Array = (new Uint8Array()).valueOf();
11+
>typedArray1 : Symbol(typedArray1, Decl(valueOfTypedArray.ts, 2, 5))
12+
>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, --, --))
13+
>(new Uint8Array()).valueOf : Symbol(Uint8Array.valueOf, Decl(lib.es5.d.ts, --, --))
14+
>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, --, --))
15+
>valueOf : Symbol(Uint8Array.valueOf, Decl(lib.es5.d.ts, --, --))
16+
17+
const typedArray2: Int16Array = (new Int16Array()).valueOf();
18+
>typedArray2 : Symbol(typedArray2, Decl(valueOfTypedArray.ts, 3, 5))
19+
>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, --, --))
20+
>(new Int16Array()).valueOf : Symbol(Int16Array.valueOf, Decl(lib.es5.d.ts, --, --))
21+
>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, --, --))
22+
>valueOf : Symbol(Int16Array.valueOf, Decl(lib.es5.d.ts, --, --))
23+
24+
const typedArray3: Uint16Array = (new Uint16Array()).valueOf();
25+
>typedArray3 : Symbol(typedArray3, Decl(valueOfTypedArray.ts, 4, 5))
26+
>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, --, --))
27+
>(new Uint16Array()).valueOf : Symbol(Uint16Array.valueOf, Decl(lib.es5.d.ts, --, --))
28+
>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, --, --))
29+
>valueOf : Symbol(Uint16Array.valueOf, Decl(lib.es5.d.ts, --, --))
30+
31+
const typedArray4: Int32Array = (new Int32Array()).valueOf();
32+
>typedArray4 : Symbol(typedArray4, Decl(valueOfTypedArray.ts, 5, 5))
33+
>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, --, --))
34+
>(new Int32Array()).valueOf : Symbol(Int32Array.valueOf, Decl(lib.es5.d.ts, --, --))
35+
>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, --, --))
36+
>valueOf : Symbol(Int32Array.valueOf, Decl(lib.es5.d.ts, --, --))
37+
38+
const typedArray5: Uint32Array = (new Uint32Array()).valueOf();
39+
>typedArray5 : Symbol(typedArray5, Decl(valueOfTypedArray.ts, 6, 5))
40+
>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, --, --))
41+
>(new Uint32Array()).valueOf : Symbol(Uint32Array.valueOf, Decl(lib.es5.d.ts, --, --))
42+
>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, --, --))
43+
>valueOf : Symbol(Uint32Array.valueOf, Decl(lib.es5.d.ts, --, --))
44+
45+
const typedArray6: Float32Array = (new Float32Array()).valueOf();
46+
>typedArray6 : Symbol(typedArray6, Decl(valueOfTypedArray.ts, 7, 5))
47+
>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, --, --))
48+
>(new Float32Array()).valueOf : Symbol(Float32Array.valueOf, Decl(lib.es5.d.ts, --, --))
49+
>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, --, --))
50+
>valueOf : Symbol(Float32Array.valueOf, Decl(lib.es5.d.ts, --, --))
51+
52+
const typedArray7: Float64Array = (new Float64Array()).valueOf();
53+
>typedArray7 : Symbol(typedArray7, Decl(valueOfTypedArray.ts, 8, 5))
54+
>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, --, --))
55+
>(new Float64Array()).valueOf : Symbol(Float64Array.valueOf, Decl(lib.es5.d.ts, --, --))
56+
>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, --, --))
57+
>valueOf : Symbol(Float64Array.valueOf, Decl(lib.es5.d.ts, --, --))
58+
59+
const typedArray8: BigInt64Array = (new BigInt64Array()).valueOf();
60+
>typedArray8 : Symbol(typedArray8, Decl(valueOfTypedArray.ts, 9, 5))
61+
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
62+
>(new BigInt64Array()).valueOf : Symbol(BigInt64Array.valueOf, Decl(lib.es2020.bigint.d.ts, --, --))
63+
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
64+
>valueOf : Symbol(BigInt64Array.valueOf, Decl(lib.es2020.bigint.d.ts, --, --))
65+
66+
const typedArray9: BigUint64Array = (new BigUint64Array()).valueOf();
67+
>typedArray9 : Symbol(typedArray9, Decl(valueOfTypedArray.ts, 10, 5))
68+
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
69+
>(new BigUint64Array()).valueOf : Symbol(BigUint64Array.valueOf, Decl(lib.es2020.bigint.d.ts, --, --))
70+
>BigUint64Array : Symbol(BigUint64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
71+
>valueOf : Symbol(BigUint64Array.valueOf, Decl(lib.es2020.bigint.d.ts, --, --))
72+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
=== tests/cases/compiler/valueOfTypedArray.ts ===
2+
// All declarations should pass, as valueOf has been specialized for all TypedArrays
3+
const typedArray0: Int8Array = (new Int8Array()).valueOf();
4+
>typedArray0 : Int8Array
5+
>(new Int8Array()).valueOf() : Int8Array
6+
>(new Int8Array()).valueOf : () => Int8Array
7+
>(new Int8Array()) : Int8Array
8+
>new Int8Array() : Int8Array
9+
>Int8Array : Int8ArrayConstructor
10+
>valueOf : () => Int8Array
11+
12+
const typedArray1: Uint8Array = (new Uint8Array()).valueOf();
13+
>typedArray1 : Uint8Array
14+
>(new Uint8Array()).valueOf() : Uint8Array
15+
>(new Uint8Array()).valueOf : () => Uint8Array
16+
>(new Uint8Array()) : Uint8Array
17+
>new Uint8Array() : Uint8Array
18+
>Uint8Array : Uint8ArrayConstructor
19+
>valueOf : () => Uint8Array
20+
21+
const typedArray2: Int16Array = (new Int16Array()).valueOf();
22+
>typedArray2 : Int16Array
23+
>(new Int16Array()).valueOf() : Int16Array
24+
>(new Int16Array()).valueOf : () => Int16Array
25+
>(new Int16Array()) : Int16Array
26+
>new Int16Array() : Int16Array
27+
>Int16Array : Int16ArrayConstructor
28+
>valueOf : () => Int16Array
29+
30+
const typedArray3: Uint16Array = (new Uint16Array()).valueOf();
31+
>typedArray3 : Uint16Array
32+
>(new Uint16Array()).valueOf() : Uint16Array
33+
>(new Uint16Array()).valueOf : () => Uint16Array
34+
>(new Uint16Array()) : Uint16Array
35+
>new Uint16Array() : Uint16Array
36+
>Uint16Array : Uint16ArrayConstructor
37+
>valueOf : () => Uint16Array
38+
39+
const typedArray4: Int32Array = (new Int32Array()).valueOf();
40+
>typedArray4 : Int32Array
41+
>(new Int32Array()).valueOf() : Int32Array
42+
>(new Int32Array()).valueOf : () => Int32Array
43+
>(new Int32Array()) : Int32Array
44+
>new Int32Array() : Int32Array
45+
>Int32Array : Int32ArrayConstructor
46+
>valueOf : () => Int32Array
47+
48+
const typedArray5: Uint32Array = (new Uint32Array()).valueOf();
49+
>typedArray5 : Uint32Array
50+
>(new Uint32Array()).valueOf() : Uint32Array
51+
>(new Uint32Array()).valueOf : () => Uint32Array
52+
>(new Uint32Array()) : Uint32Array
53+
>new Uint32Array() : Uint32Array
54+
>Uint32Array : Uint32ArrayConstructor
55+
>valueOf : () => Uint32Array
56+
57+
const typedArray6: Float32Array = (new Float32Array()).valueOf();
58+
>typedArray6 : Float32Array
59+
>(new Float32Array()).valueOf() : Float32Array
60+
>(new Float32Array()).valueOf : () => Float32Array
61+
>(new Float32Array()) : Float32Array
62+
>new Float32Array() : Float32Array
63+
>Float32Array : Float32ArrayConstructor
64+
>valueOf : () => Float32Array
65+
66+
const typedArray7: Float64Array = (new Float64Array()).valueOf();
67+
>typedArray7 : Float64Array
68+
>(new Float64Array()).valueOf() : Float64Array
69+
>(new Float64Array()).valueOf : () => Float64Array
70+
>(new Float64Array()) : Float64Array
71+
>new Float64Array() : Float64Array
72+
>Float64Array : Float64ArrayConstructor
73+
>valueOf : () => Float64Array
74+
75+
const typedArray8: BigInt64Array = (new BigInt64Array()).valueOf();
76+
>typedArray8 : BigInt64Array
77+
>(new BigInt64Array()).valueOf() : BigInt64Array
78+
>(new BigInt64Array()).valueOf : () => BigInt64Array
79+
>(new BigInt64Array()) : BigInt64Array
80+
>new BigInt64Array() : BigInt64Array
81+
>BigInt64Array : BigInt64ArrayConstructor
82+
>valueOf : () => BigInt64Array
83+
84+
const typedArray9: BigUint64Array = (new BigUint64Array()).valueOf();
85+
>typedArray9 : BigUint64Array
86+
>(new BigUint64Array()).valueOf() : BigUint64Array
87+
>(new BigUint64Array()).valueOf : () => BigUint64Array
88+
>(new BigUint64Array()) : BigUint64Array
89+
>new BigUint64Array() : BigUint64Array
90+
>BigUint64Array : BigUint64ArrayConstructor
91+
>valueOf : () => BigUint64Array
92+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @target: es2020
2+
3+
// All declarations should pass, as valueOf has been specialized for all TypedArrays
4+
const typedArray0: Int8Array = (new Int8Array()).valueOf();
5+
const typedArray1: Uint8Array = (new Uint8Array()).valueOf();
6+
const typedArray2: Int16Array = (new Int16Array()).valueOf();
7+
const typedArray3: Uint16Array = (new Uint16Array()).valueOf();
8+
const typedArray4: Int32Array = (new Int32Array()).valueOf();
9+
const typedArray5: Uint32Array = (new Uint32Array()).valueOf();
10+
const typedArray6: Float32Array = (new Float32Array()).valueOf();
11+
const typedArray7: Float64Array = (new Float64Array()).valueOf();
12+
const typedArray8: BigInt64Array = (new BigInt64Array()).valueOf();
13+
const typedArray9: BigUint64Array = (new BigUint64Array()).valueOf();

0 commit comments

Comments
 (0)