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

Typed Promise #4116

Open
MOZGIII opened this issue Sep 17, 2024 · 0 comments
Open

Typed Promise #4116

MOZGIII opened this issue Sep 17, 2024 · 0 comments
Labels
breaking-change Tracking breaking changes for the next major version bump (if ever) enhancement

Comments

@MOZGIII
Copy link
Contributor

MOZGIII commented Sep 17, 2024

Motivation

js_sys::Promise -> js_sys::Promise<T = JsValue>

Better type system has obvious benefits.

Proposed Solution

  1. Add a generic to the js_sys::Promise<T = JsValue>
  2. Adjust the calls like then to take a Promise<T> and callback from T and return a differently-typed Promise<U>.
  3. Adjust TypeScript codegen to allow specifying the T type (currently it is Promise<any>).

Alternatives

js_sys::Promise -> js_sys::Promise<T = JsValue, E = JsValue> - where E is the typed rejection; this is not how TypeScript types them though, and there are issues in general with errors typing due to the JavaScript language model itself.

Additional Context

I want to replace impl Future<Output = T> with js_sys::Promise<T> in my bindings where applicable.

@daxpedda daxpedda added the breaking-change Tracking breaking changes for the next major version bump (if ever) label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Tracking breaking changes for the next major version bump (if ever) enhancement
Projects
None yet
Development

No branches or pull requests

2 participants