Skip to content

I think that this is a bad approach #2

@zloirock

Description

@zloirock

The design of promises is based on the principle of duck typing and interaction between promises from different authors on the thenable protocol. Native promises are not the only popular promises on the web. For example, promises from babel-runtime -> core-js-pure are wrapped and, in some cases, are not native. Bluebird and other userland Promise implementations are still very popular. Even jQuery could return a promise that will work by the thenable protocol, but will not be a native promise.

Your code could get an instance of alternative promise implementations from third-party code and something like let foo = Promise.isPromise(bar) ? await bar : bar will be broken.

Error.isError? It works with userland errors since they are native error subclasses. That's false for promises.

Promise.isThenable that will check the existence of a callable .then will work much better for the case of optimization.

In my vision, adding Promise.isPromise could be good for native class identification in low-level utilities, together and at the same time with Map.isMap and all the rest similar constructors / cases, but not for optimization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions