Hacker News new | ask | show | jobs
by adrianhel 2237 days ago
There should be a Promise.isThenable or Promise.is. Strictly speaking this library checks if a value is a thenable.

With optional chaining I would however use this check:

    typeof x?.then === 'function'
Or if I was code golfin:

    x?.then?.call
The first case does not account for built in prototype extensions and the second has false positives with certain data structures.

So the function in is-promise should be available as Promise.isThenable or Promise.is.