Title: [BridgeJS] Support @JS var declarations for global scope imports · Issue #466 · swiftwasm/JavaScriptKit · GitHub
Open Graph Title: [BridgeJS] Support @JS var declarations for global scope imports · Issue #466 · swiftwasm/JavaScriptKit
X Title: [BridgeJS] Support @JS var declarations for global scope imports · Issue #466 · swiftwasm/JavaScriptKit
Description: Motivation Currently, importing JavaScript APIs from the global scope requires users to write TypeScript declaration files and import APIs through the standard BridgeJS workflow. For simple use cases where users only need to access a few...
Open Graph Description: Motivation Currently, importing JavaScript APIs from the global scope requires users to write TypeScript declaration files and import APIs through the standard BridgeJS workflow. For simple use cas...
X Description: Motivation Currently, importing JavaScript APIs from the global scope requires users to write TypeScript declaration files and import APIs through the standard BridgeJS workflow. For simple use cas...
Opengraph URL: https://github.com/swiftwasm/JavaScriptKit/issues/466
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BridgeJS] Support @JS var declarations for global scope imports","articleBody":"## Motivation\n\nCurrently, importing JavaScript APIs from the global scope requires users to write TypeScript declaration files and import APIs through the standard BridgeJS workflow. For simple use cases where users only need to access a few well-known global APIs like `console.log()` or `document.getElementById()`, this approach can feel heavyweight and requires additional setup steps.\n\n## Proposed Solution\n\nAllow users to declare global scope imports directly in Swift using `@JS var` declarations with protocol interfaces, eliminating the need for separate `.d.ts` files for simple global API access.\n\n## High-level API\n\n```swift\n@JS protocol JSConsole {\n func log(_ message: String) throws(JSException)\n func error(_ message: String) throws(JSException)\n}\n\n@JSGetter(from: .global) var console: JSConsole\n\n@JS class JSElement {\n var innerHTML: String { get set }\n func addEventListener(_ event: String, _ handler: @escaping () -\u003e Void) throws(JSException)\n}\n\n@JS protocol JSDocument {\n func getElementById(_ id: String) throws(JSException) -\u003e JSElement?\n}\n\n@JS(from: .global, jsName: \"document\") var jsDocument: JSDocument\n\n@JSImport(from: .module(\"uuid\"), jsName: \"v4\")\nfunc uuidv4() throws(JSException) -\u003e String\n\n@JSImport(from: .module(\"./custom-component.js\"), jsName: \"defineCustomComponents\")\nfunc jsDefineCustomComponents() throws(JSException)\n\n@JS func run() {\n print(uuidv4())\n jsDefineCustomComponents()\n}\n\n```\n\n## Implementation\n\nThis feature would require adding a macro plugin to support `@JS var [name]: [Type]` declarations that generates getter/setter accessors interacting with the code generated by `@JS protocol`\n\nIf it works well, we might be able to make ImportTS just to generate `@JS` annotated Swift code and centralize ABI-facing code in ExportSwift","author":{"url":"https://github.com/kateinoigakukun","@type":"Person","name":"kateinoigakukun"},"datePublished":"2025-11-09T07:36:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/466/JavaScriptKit/issues/466"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9df9d6d9-bca6-19b0-8944-fc68dfc61d5a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DDC4:3CF7C2:42E6485:5A2AF4F:697B1C64 |
| html-safe-nonce | 7786dda5ff58d3518df3a236a882b900357311ae68d84daeaf6da8c934c45fa9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEREM0OjNDRjdDMjo0MkU2NDg1OjVBMkFGNEY6Njk3QjFDNjQiLCJ2aXNpdG9yX2lkIjoiMzI5Mjk5MjIwNDAzMjM4NDEwMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 021c3c14429c1aac5d56b398838d39c72cc38147e93c18a6d7fe7118ce4b0e87 |
| hovercard-subject-tag | issue:3604564880 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/swiftwasm/JavaScriptKit/466/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b8f178f8fd9eddf9f3550ba37d93a3598517067f25be93954ecd221a506c2dcc/swiftwasm/JavaScriptKit/issues/466 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b8f178f8fd9eddf9f3550ba37d93a3598517067f25be93954ecd221a506c2dcc/swiftwasm/JavaScriptKit/issues/466 |
| og:image:alt | Motivation Currently, importing JavaScript APIs from the global scope requires users to write TypeScript declaration files and import APIs through the standard BridgeJS workflow. For simple use cas... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kateinoigakukun |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7ce8ed0a54c4730aeca4e6abacfc6490365fc42e25480b86883054df3f9181c8 |
| turbo-cache-control | no-preview |
| go-import | github.com/swiftwasm/JavaScriptKit git https://github.com/swiftwasm/JavaScriptKit.git |
| octolytics-dimension-user_id | 49500752 |
| octolytics-dimension-user_login | swiftwasm |
| octolytics-dimension-repository_id | 244832006 |
| octolytics-dimension-repository_nwo | swiftwasm/JavaScriptKit |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 244832006 |
| octolytics-dimension-repository_network_root_nwo | swiftwasm/JavaScriptKit |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d7bfc78137af9a4828305e52ab993fce981d7085 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width