Skip to content

Commit b2d5293

Browse files
Fix typecheck error around TypedArray
1 parent 63cdb6b commit b2d5293

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

Runtime/src/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
ExportedFunctions,
55
ref,
66
pointer,
7-
TypedArray,
87
MAIN_THREAD_TID,
98
} from "./types.js";
109
import * as JSValue from "./js-value.js";
@@ -501,12 +500,16 @@ export class SwiftRuntime {
501500
return func_ref;
502501
},
503502

504-
swjs_create_typed_array: (
503+
swjs_create_typed_array: <T extends Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | BigInt64Array | BigUint64Array | Float32Array | Float64Array | Uint8ClampedArray>(
505504
constructor_ref: ref,
506505
elementsPtr: pointer,
507506
length: number
508507
) => {
509-
const ArrayType: TypedArray =
508+
type TypedArrayConstructor = {
509+
new (buffer: ArrayBuffer, byteOffset: number, length: number): T;
510+
new (): T;
511+
};
512+
const ArrayType: TypedArrayConstructor =
510513
this.memory.getObject(constructor_ref);
511514
if (length == 0) {
512515
// The elementsPtr can be unaligned in Swift's Array

Runtime/src/types.ts

-12
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ export const enum LibraryFeatures {
2828
WeakRefs = 1 << 0,
2929
}
3030

31-
export type TypedArray =
32-
| Int8ArrayConstructor
33-
| Uint8ArrayConstructor
34-
| Int16ArrayConstructor
35-
| Uint16ArrayConstructor
36-
| Int32ArrayConstructor
37-
| Uint32ArrayConstructor
38-
| BigInt64ArrayConstructor
39-
| BigUint64ArrayConstructor
40-
| Float32ArrayConstructor
41-
| Float64ArrayConstructor;
42-
4331
export function assertNever(x: never, message: string) {
4432
throw new Error(message);
4533
}

0 commit comments

Comments
 (0)