Skip to content

BridgeJS: Add JSTypedArray as a recognized BridgeJS type#746

Merged
kateinoigakukun merged 1 commit into
mainfrom
krodak/js-typed-array-bridgejs
May 13, 2026
Merged

BridgeJS: Add JSTypedArray as a recognized BridgeJS type#746
kateinoigakukun merged 1 commit into
mainfrom
krodak/js-typed-array-bridgejs

Conversation

@krodak
Copy link
Copy Markdown
Member

@krodak krodak commented May 13, 2026

Overview

Add JSTypedArray<T> and convenience typealiases (JSUint8Array, JSFloat32Array, etc.) as recognized BridgeJS types. Users can now use typed arrays directly in @JS function signatures to get native TypedArray types in the generated TypeScript declarations.

Both the generic form and typealiases work:

@JS func processData(_ data: JSTypedArray<UInt8>) -> JSTypedArray<UInt8> { ... }
@JS func processData(_ data: JSUint8Array) -> JSUint8Array { ... }  // equivalent

Generated TypeScript:

processData(data: Uint8Array): Uint8Array;

Bridging is reference-based — passes the JSObject ID across the boundary with no data copying. The TypedArray lives on the JS heap. This follows the same pattern as JSPromise, which is already pre-seeded as a known BridgeJS type.

1. JSTypedArray.swift — 8 convenience typealiases: JSInt8Array, JSUint8Array, JSInt16Array, JSUint16Array, JSInt32Array, JSUint32Array, JSFloat32Array, JSFloat64Array.

2. SwiftToSkeleton.swift — Pre-seed typed array types in the type resolver (same as JSPromise). Recognize JSTypedArray<T> generic form via element name → typealias mapping.

3. BridgeJSLink.swift — Map Swift typealias names to JS TypedArray constructor names in tsType (e.g., JSUint8ArrayUint8Array).

4. TS2Swift/processor.js — Map TypeScript TypedArray types to Swift typealiases in the TS importer, preventing import of the full TypedArray API surface from TypeScript's stdlib.

5. E2e testsJSTypedArrayTests.swift + JSTypedArrayTests.mjs with round-trip tests for Uint8Array, Float32Array, Float64Array, Int32Array from both Swift and JS sides.

@krodak krodak self-assigned this May 13, 2026
@krodak krodak requested a review from kateinoigakukun May 13, 2026 10:28
@MaxDesiatov MaxDesiatov added the enhancement New feature or request label May 13, 2026
Copy link
Copy Markdown
Member

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything in documentation files that could be updated here?

Copy link
Copy Markdown
Member

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems quite straightforward, thanks! LGTM modulo possible documentation improvements.

@krodak krodak force-pushed the krodak/js-typed-array-bridgejs branch from 9aaa777 to 90abc67 Compare May 13, 2026 11:06
Add JSInt8Array, JSUint8Array, JSInt16Array, JSUint16Array, JSInt32Array,
JSUint32Array, JSFloat32Array, JSFloat64Array typealiases and pre-seed
them in SwiftToSkeleton so BridgeJS recognizes them in @js signatures.

Users can now write:
  @js func processData(_ data: JSUint8Array) -> JSUint8Array

Generated TypeScript uses native typed array names:
  processData(data: Uint8Array): Uint8Array

Bridging is reference-based (passes JSObject ID, no data copying).
Follows the existing JSPromise pre-seeding pattern.
@krodak krodak force-pushed the krodak/js-typed-array-bridgejs branch from 90abc67 to ce4242a Compare May 13, 2026 11:09
@krodak
Copy link
Copy Markdown
Member Author

krodak commented May 13, 2026

@MaxDesiatov docs added 🫡

Copy link
Copy Markdown
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kateinoigakukun kateinoigakukun merged commit fc672e7 into main May 13, 2026
13 checks passed
@kateinoigakukun kateinoigakukun deleted the krodak/js-typed-array-bridgejs branch May 13, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants