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

parse returns a promise although the type does not indicate so #155

Open
altinokdarici opened this issue Jul 31, 2023 · 1 comment
Open

Comments

@altinokdarici
Copy link

In parse.ts file, the blow code snippet returns a promise.

 if (!wasm)
    // actually returns a promise if init hasn't resolved (not type safe).
    // casting to avoid a breaking type change.
    return init.then(() => parse(source)) as unknown as ReturnType<typeof parse>;

This type hack causes issues on the consumption side. We call the parse function without awaiting as it's indicated by type system. However, we figured that parse may return Promise in the run time.

@guybedford
Copy link
Owner

The function is supposed to be synchronous if you've awaited init, but if you haven't awaited init it should be async.

I think this was changed in the TypeScript migration. I personally like having the sync version, so would suggest we change the code to match the types like:

if (!initialized)
  return init.then(() => ...);
// ... parse

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