winglang/wing

TypeScript extern annotation is generated wrong for functions returning optionals

Open

#7,015 opened on 2024幎8月12日

GitHub で芋る
 (1 comment) (1 reaction) (0 assignees)TypeScript (214 forks)github user discovery
good first issue🐛 bug🛠 compiler

Repository metrics

Stars
 (5,385 stars)
PR merge metrics
 (30d に merged PR はありたせん)

説明

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.

コントリビュヌタヌガむド