Skip to content

BridgeJS: Add missing function keyword for namespace function declarations in TypeScript#592

Merged
kateinoigakukun merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:krodak/function-ts-fix
Feb 5, 2026
Merged

BridgeJS: Add missing function keyword for namespace function declarations in TypeScript#592
kateinoigakukun merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:krodak/function-ts-fix

Conversation

@krodak
Copy link
Member

@krodak krodak commented Feb 5, 2026

Overview

TIL 😅
BridgeJS was generating invalid TypeScript declarations for functions inside namespace blocks. The generated code looked like:

declare global {
    namespace Utils {
        namespace String {
            uppercase(text: string): string;  // ❌ Invalid TypeScript
        }
    }
}

This is a syntax error in TypeScript. Unlike class methods, functions inside TypeScript namespace declarations require the explicit function keyword.

Why this wasn't caught:
JavaScriptKit's tsconfig.json uses "skipLibCheck": true, which skips type-checking of declaration files (.d.ts). The JavaScript E2E tests also passed because JavaScript doesn't have namespace - it only sees the compiled runtime objects.

Project which runs strict TypeScript type-checking (tsc --noEmit) without skipLibCheck fails due to that

Fix

Added the function keyword prefix when generating function declarations inside namespaces:

declare global {
    namespace Utils {
        namespace String {
            function uppercase(text: string): string;  // ✅ Valid TypeScript
        }
    }
}

@kateinoigakukun kateinoigakukun merged commit b1fb45e into swiftwasm:main Feb 5, 2026
11 checks passed
@krodak krodak deleted the krodak/function-ts-fix branch February 5, 2026 14:48
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