winglang/wing

TypeScript extern annotation is generated wrong for functions returning optionals

Open

#7.015 geöffnet am 12. Aug. 2024

Auf GitHub ansehen
 (1 Kommentar) (1 Reaktion) (0 zugewiesene Personen)TypeScript (214 Forks)github user discovery
good first issue🐛 bug🛠️ compiler

Repository-Metriken

Stars
 (5.385 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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.

Contributor Guide