winglang/wing

TypeScript extern annotation is generated wrong for functions returning optionals

Open

#7,015 创建于 2024年8月12日

在 GitHub 查看
 (1 评论) (1 反应) (0 负责人)TypeScript (214 fork)github user discovery
good first issue🐛 bug🛠️ compiler

仓库指标

Star
 (5,385 star)
PR 合并指标
 (30 天内没有已合并 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.

贡献者指南