winglang/wing
View on GitHubTypeScript extern annotation is generated wrong for functions returning optionals
Open
#7,015 opened on Aug 12, 2024
good first issue🐛 bug🛠️ compiler
Repository metrics
- Stars
- (5,385 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
I tried this:
// main.w
class Foo {
static extern "./foo.ts" asStringToken(producer: (): str?): str;
}
// foo.extern.d.ts (generated by compiler)
export default interface extern {
asStringToken: (producer: () => string | void) => string,
}
// foo.ts
import { Lazy } from "cdktf";
import types from "./function-aws.extern";
export const asStringToken: types["asStringToken"] = (producer) => {
return Lazy.stringValue({ produce: producer });
};
This happened:
I got a TypeScript type checking error in my IDE:
Type '() => string | void' is not assignable to type '(context: IResolveContext) => string | undefined'.
I expected this:
I expected the generated type annotation to have string | undefined instead of string | void
Is there a workaround?
No response
Anything else?
No response
Wing Version
0.82.5
Node.js Version
No response
Platform(s)
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.