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

support result in types generation #532

Open
ctaggart opened this issue Dec 1, 2024 · 1 comment
Open

support result in types generation #532

ctaggart opened this issue Dec 1, 2024 · 1 comment

Comments

@ctaggart
Copy link

ctaggart commented Dec 1, 2024

In changes my WIT definition from:

create-program: func(options: compiler-options) -> program;

to return a result:

create-program: func(options: compiler-options) -> result<program, string>;

but the generated .d.ts from bunx jco types wit -o . still has:

export function createProgram(options: CompilerOptions): Program;

I was hoping that it would show up as:

export function createProgram(options: CompilerOptions): Result<Program, string>;

I'm not exactly sure where Result would be defined, but I see a it defined a couple of times in preview-2shim as:

export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@guybedford
Copy link
Collaborator

Just like top-level optionals become possibly nullish, top-level results utilize the JS error itself.

So if you want to create an error result you can do throw 'error-string'.

We could possibly have a customization option to turn this off, but it's also useful to be able to interop with JS error handling paths.

We should also have proper documentation of the type conversions like this, this is still tracking in #418.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants