winglang / wing

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

Invalid TypeScript definitions for structs returned by inflight externs #6495

Open eladb opened 1 month ago

eladb commented 1 month ago

I tried this:

// main.w

bring cloud;

struct Output {
  myBucket: cloud.Bucket;
}

class X {
  extern "./source.ts" pub static inflight foo(b: cloud.Bucket): Output;
}

This happened:

The generated .d.ts file looks like this:

export default interface extern {
  foo: (b: Bucket$Inflight) => Promise<Output>,
}

// ...

export interface Output {
  readonly myBucket: Bucket;
}

I expected this:

I expected Output to include Bucket$Inflight.

Is there a workaround?

No response

Anything else?

No response

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Community Notes

yoav-steinberg commented 4 weeks ago

I'm not sure what would be a good solution here. The problem stems from the fact that structs can contains classes (which goes againes their definition in the spec, btw, as "data bags"). This is a a whole other discussion we need to have (@Chriscbr...).

Since Output contains a Bucket class we don't know if it should contain the preflight or inflight version of Bucket. Or maybe we need to create 2 Outputs once for each phase and be smarter about how to lift structs?

MarkMcCulloh commented 4 weeks ago

structs can contain classes

Related discussion https://github.com/winglang/wing/discussions/5102

Chriscbr commented 4 weeks ago

How about we suppose that in the TypeScript world we generate both Output and Output$Inflight, which will contain Bucket and Bucket$Inflight respectively.

In the example, the compiler could determine it needs to use Output$Inflight in the "foo" method since it's an inflight function.

@yoav-steinberg WDYT?