winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.06k stars 198 forks source link

Import typescript files with `bring` #6042

Open MarkMcCulloh opened 8 months ago

MarkMcCulloh commented 8 months ago

Use Case

The current mechanism to import javascript/typescript is extern. Among several DX issues, a primary difficulty is that it forces the user to declare types for the module upfront within the consuming wing file. This takes the source of truth for types away from the implementation. Instead, we can import typescript files like wing files to allow them to be the source of truth:

bring "helper.ts" as helper;

Proposed Solution

To limit the implementation difficulty, I would propose the following limitations/simplifications:

Ideally, the naive implementation of

  1. Parse single typescript file
  2. Visit all exports to build up a wing SymbolEnv with type info

The above restrictions basically already match existing extern restrictions.

Implementation Notes

Depends on https://github.com/winglang/wing/issues/3013 to run ESM+typescript in preflight.

https://docs.rs/oxc_parser/latest/oxc_parser/ and https://docs.rs/oxc_semantic/latest/oxc_semantic/ could be invaluable here

Component

No response

Community Notes

github-actions[bot] commented 5 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!