winglang / winglang/wing

Generics support

Open
#104 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

📐 language-design 📜 lang-spec-impl roadmap
Dominant language
TypeScript
Stars
5.4k
Forks
215
Avg merge
2h 9m
Merged PRs (30d)
27

Description

Supporting Generics in Wing could be used to provide useful errors between preflight and inflight code:

bring cloud;

struct A {
  field1: str;
  field2: num;
}

let bucket = new cloud.Bucket();
let queue = new cloud.Queue<A>();

let processor = new cloud.Function((event: Array<A>) ~> {
    print("Received a batch where the first message is ${event[0]}");
});
queue.onMessage(processor);
bucket.onUpload(processor); // ERROR: Bucket.onUpload expects an argument of type Function<BucketUploadEvent> but received Function<Array<A>>

let notifier: cloud.Function<cloud.BucketUploadEvent> = new cloud.Function((event: cloud.BucketUploadEvent) ~> {
    print("File ${event.file} was uploaded on {event.date}");
});
bucket.onUpload(notifier);
queue.onMessage(notifier); // ERROR: Queue.onMessage expects an argument of type Function<Array<A>> but received Function<BucketUploadEvent>

To support JSII interoperability, I'd propose that during compilation we might be able to perform type erasure like Java that convert type paramters like T into any, and add JSII metadata that details any of the erased type information.

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 files, tests, or entry points. Start by reviewing the compiler's type-checking path and JSII interoperability design; done should include generic type checking between preflight and inflight code and metadata for erased type information.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.