winglang / winglang/wing

Support importing values/constants through `extern`

Open
#6,989 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

✨ enhancement 📐 language-design 🛠️ compiler needs-discussion
Dominant language
TypeScript
Stars
5.4k
Forks
215
Avg merge
2h 9m
Merged PRs (30d)
27

Description

Use Case

Right now extern can be used to bring functions from the TypeScript/JavaScript, but it would be handy to be able to bring other kinds of values like arrays, strings, objects satisfying interfaces, etc.

It's possible to work around these limitations today by defining an extern function that returns the value you'd want, but it's an unnecessary restriction.

Proposed Solution

This will require some kind of alternative syntax for extern, e.g.

Syntax idea 1

bring extern "./foo.ts" {
  myValue: str;
  myOtherValue: Array<num>;
  myObj: IFoo;
};

log(myValue);
myObj.insert("region", "us-east-1");

Syntax idea 2

const foo = extern "./foo.ts" {
  myValue: str;
  myOtherValue: Array<num>;
  myObj: IFoo;
};

log(foo.myOtherValue);
foo.myObj.insert("region", "us-east-1");

Syntax idea 3

const foo = @extern("./foo.ts", {
  myValue: str;
  myOtherValue: Array<num>;
  myObj: IFoo;
});

log(foo.myOtherValue);
foo.myObj.insert("region", "us-east-1");

I think the syntaxes above need some work. An ideal syntax would support both use cases where the extern file exports an individual value and where it exports a complex object with multiple fields as shown above.

Implementation Notes

No response

Component

Language Design

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 Discord.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no implementation files, tests, or entry points. Start by reviewing the three proposed extern syntaxes and the Language Design component; the work is done only after a syntax is agreed that supports imported individual values and complex objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.