Skip to content

BridgeJS: Include properties and release() in declare global class stubs#693

Merged
krodak merged 2 commits intoswiftwasm:mainfrom
PassiveLogic:kr/fix-declare-global-class-stubs
Mar 5, 2026
Merged

BridgeJS: Include properties and release() in declare global class stubs#693
krodak merged 2 commits intoswiftwasm:mainfrom
PassiveLogic:kr/fix-declare-global-class-stubs

Conversation

@krodak
Copy link
Member

@krodak krodak commented Mar 5, 2026

Overview

When exposeToGlobal: true is set in bridge-js.config.json, BridgeJS emits a declare global block so TypeScript knows the exported Swift classes exist on globalThis. These stubs were generated with constructor signatures and methods, but two things were always missing:

  • Instance properties (@JS var declarations on the class)
  • release(): void (inherited from SwiftHeapObject by every exported class)

This meant that accessing an instance through the globalThis path produced a TypeScript type with no properties and no release(), forcing consumers to use as unknown as TheInterface casts to recover full typing.

Before (declare global stub for a class with a precision property):

declare global {
    namespace Utils {
        class Converter {
            constructor();
            toString(value: number): string;
            // precision: number  ← missing
            // release(): void    ← missing
        }
    }
}

After:

declare global {
    namespace Utils {
        class Converter {
            constructor();
            toString(value: number): string;
            precision: number;
            release(): void;
        }
    }
}

The fix is a small addition to generateNamespaceDeclarationsForNode in BridgeJSLink.swift: after emitting methods, emit non-static properties sorted by name, then always append release(): void.

Three snapshot files are updated: Namespaces.Global.d.ts, EnumNamespace.Global.d.ts, and MixedModules.d.ts.

@krodak krodak merged commit ba66ff1 into swiftwasm:main Mar 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants