Skip to content

Commit 24a908d

Browse files
authored
Improve valueof definitions. Add some extra tests (#2390)
1 parent 71b02d4 commit 24a908d

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

std/assembly/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,9 +1349,9 @@ declare abstract class i31 {
13491349
/** Macro type evaluating to the underlying native WebAssembly type. */
13501350
declare type native<T> = T;
13511351
/** Special type evaluating the indexed access index type. */
1352-
declare type indexof<T extends unknown[]> = keyof T;
1352+
declare type indexof<T extends ArrayLike<unknown>> = keyof T;
13531353
/** Special type evaluating the indexed access value type. */
1354-
declare type valueof<T extends unknown[]> = T[0];
1354+
declare type valueof<T extends ArrayLike<unknown>> = T[0];
13551355
/** A special type evaluated to the return type of T if T is a callable function. */
13561356
declare type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
13571357
/** A special type evaluated to the return type of T if T is a callable function. */

tests/compiler/indexof-valueof.debug.wat

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@
7373
drop
7474
i32.const 1
7575
drop
76+
i32.const 0
77+
i32.eqz
78+
drop
79+
i32.const 4
80+
i32.const 4
81+
i32.eq
82+
drop
83+
i32.const 1
84+
drop
85+
i32.const 1
86+
drop
87+
i32.const 8
88+
i32.const 8
89+
i32.eq
90+
drop
91+
i32.const 1
92+
drop
7693
i32.const 1
7794
drop
7895
i32.const 1

tests/compiler/indexof-valueof.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ assert(sizeof<indexof<Float32Array>>() == 4); // i32
3939
assert(isInteger<valueof<Uint8ClampedArray>>());
4040
assert(!isSigned<valueof<Uint8ClampedArray>>());
4141
assert(sizeof<valueof<Uint8ClampedArray>>() == 1);
42+
assert(isFloat<valueof<Float32Array>>());
43+
assert(!isInteger<valueof<Float32Array>>());
44+
assert(sizeof<valueof<Float32Array>>() == 4);
45+
assert(isInteger<valueof<Int64Array>>());
46+
assert(isSigned<valueof<Int64Array>>());
47+
assert(sizeof<valueof<Int64Array>>() == 8);
4248

4349
// map indexes
4450
assert(isInteger<indexof<Map<i32,i32>>>());

0 commit comments

Comments
 (0)