From b2d5293f8a9ea7758bf28d6fd099b28844400491 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 24 Apr 2025 06:19:14 +0000 Subject: [PATCH] Fix typecheck error around TypedArray --- Runtime/src/index.ts | 9 ++++++--- Runtime/src/types.ts | 12 ------------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/Runtime/src/index.ts b/Runtime/src/index.ts index 05c2964f..a747dec1 100644 --- a/Runtime/src/index.ts +++ b/Runtime/src/index.ts @@ -4,7 +4,6 @@ import { ExportedFunctions, ref, pointer, - TypedArray, MAIN_THREAD_TID, } from "./types.js"; import * as JSValue from "./js-value.js"; @@ -501,12 +500,16 @@ export class SwiftRuntime { return func_ref; }, - swjs_create_typed_array: ( + swjs_create_typed_array: ( constructor_ref: ref, elementsPtr: pointer, length: number ) => { - const ArrayType: TypedArray = + type TypedArrayConstructor = { + new (buffer: ArrayBuffer, byteOffset: number, length: number): T; + new (): T; + }; + const ArrayType: TypedArrayConstructor = this.memory.getObject(constructor_ref); if (length == 0) { // The elementsPtr can be unaligned in Swift's Array diff --git a/Runtime/src/types.ts b/Runtime/src/types.ts index a8872f80..b8345cdf 100644 --- a/Runtime/src/types.ts +++ b/Runtime/src/types.ts @@ -28,18 +28,6 @@ export const enum LibraryFeatures { WeakRefs = 1 << 0, } -export type TypedArray = - | Int8ArrayConstructor - | Uint8ArrayConstructor - | Int16ArrayConstructor - | Uint16ArrayConstructor - | Int32ArrayConstructor - | Uint32ArrayConstructor - | BigInt64ArrayConstructor - | BigUint64ArrayConstructor - | Float32ArrayConstructor - | Float64ArrayConstructor; - export function assertNever(x: never, message: string) { throw new Error(message); }