Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print optional arguments in TypeScript as foo?: type #21

Open
alexcrichton opened this issue Oct 27, 2022 · 1 comment
Open

Print optional arguments in TypeScript as foo?: type #21

alexcrichton opened this issue Oct 27, 2022 · 1 comment
Labels
enhancement New feature or request TypeScript TypeScript output generation

Comments

@alexcrichton
Copy link
Member

Right now

foo: func(a: option<u32>)

generates:

export interface Input {
  foo(a: number | null): void;
}

where it should ideally instead generate:

export interface Input {
  foo(a?: number): void;
}
@alexcrichton alexcrichton transferred this issue from bytecodealliance/wit-bindgen Jan 26, 2023
@guybedford guybedford added the TypeScript TypeScript output generation label Sep 20, 2023
@yoshuawuyts yoshuawuyts added the enhancement New feature or request label Oct 18, 2023
@lucasavila00
Copy link

lucasavila00 commented Oct 26, 2023

I think the proposed approach will not work due to following - or it should fall back to unions in such cases

// foo: func(a: option<u32>, b: u32)

export interface Input {
  foo(a?: number, b: number): void;
  //              ^ A required parameter cannot follow an optional parameter.ts(1016)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request TypeScript TypeScript output generation
Projects
None yet
Development

No branches or pull requests

4 participants