Skip to content

Typed Promise #4116

Open
Open
@MOZGIII

Description

@MOZGIII

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking-changeTracking breaking changes for the next major version bump (if ever)enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions