winglang/wing

TypeScript extern annotation is generated wrong for functions returning optionals

Open

#7 015 ouverte le 12 août 2024

Voir sur GitHub
 (1 commentaire) (1 réaction) (0 assignés)TypeScript (214 forks)github user discovery
good first issue🐛 bug🛠️ compiler

Métriques du dépôt

Stars
 (5 385 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

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.

Guide contributeur