Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript inflights (Enhanced extern) #5868

Closed
MarkMcCulloh opened this issue Mar 8, 2024 · 1 comment · Fixed by #5967
Closed

TypeScript inflights (Enhanced extern) #5868

MarkMcCulloh opened this issue Mar 8, 2024 · 1 comment · Fixed by #5967
Assignees
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl 📜 typescript Issues relating to Typescript for Wing

Comments

@MarkMcCulloh
Copy link
Contributor

Use Case

To make use of existing huge/mature ecosystems, writing inflight functions in javascript/typescript would be a huge boost in the usability and adoption of the wing toolchain.

// handler.ts
// generated types
import type extern from "./handler.ts.extern"

export default {
  handler: async (event) => {
    console.log(event);
  }
} satisfies extern;
// main.w
bring cloud;

class MyResource {
  static inflight extern "./handler.ts" handler(event: str);
  myFunction: cloud.Function;
  new() {
    this.myFunction = new cloud.Function(MyResource.handler);
  }
}

new MyResource();

Proposed Solution

Enhance the existing extern functionality with 2 features:

  1. E2E type safety. The wing compiler should generate a type contract for the extern file to satisfy. This should include inflight clients for lifted resources.
  2. A way to lift resources into the typescript. Related to Mechanism for explicitly qualifying lifting #76
  3. Ability to pass extern function as arguments expecting inflight closures

Implementation Notes

No response

Component

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Slack.
@MarkMcCulloh MarkMcCulloh added ✨ enhancement New feature or request 🛠️ compiler Compiler needs-discussion Further discussion is needed prior to impl 📜 typescript Issues relating to Typescript for Wing labels Mar 8, 2024
@mergify mergify bot closed this as completed in #5967 Mar 18, 2024
mergify bot pushed a commit that referenced this issue Mar 18, 2024
Closes #5868 (except the static part, but that's not critical for the use-case)

Compiling a wing project will now generate .d.ts files for the contract between wing and extern files. These .d.ts files are fully self-contained.

The code for this looks similar to existing dtsification code, but there are couple important distinctions that made it feel useful to separate it:
1. The new code only access to type information rather than the original ASTs
2. The new code is intentionally generating types in the same file as needed instead of producing references

Misc:
- No longer emit any files if any errors occur during compiliation
- Internally change extern to use Utf8PathBuff
- Converted some `examples` externs into typescript (I would love to do the rest, but need #3013)

Note that this may be a breaking change: extern types must be consistent. So in one class you refer to an extern as returning a `str` and in another it returns a Json, that will now be a compiler error.

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.61.13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl 📜 typescript Issues relating to Typescript for Wing
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants