You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My personal opinion is no. With the current semantics:
match(value){when(Promise){/* real Promise */}when(Promise|{then: Function}){/* thenable */}}
With loosened semantics:
functionisPromise(value){constp=Promise.resolve(p);p.then(()=>{},()=>{});// to avoid unhandled rejectionsreturnvalue===p;}match(value){when(Promise)if(isPromise(value)){/* real Promise */}when(Promise){/* thenable */}}
The latter seems much worse to me than the former.
Also agree on no - it would be surprising if Promise, alone among the built-ins, accepted random objects that weren't Promise objects.
If authors want to handle thenables they can do so themselves. The thenable-handling should be considered a legacy-compatibility thing (we did it to help early adoption, as it gave us compatibility with userland Promise libraries), and not something we care about going forward except for consistency in some cases.
Reacted by Jordan Harband, Ross Kirsling, Bo Lingen, Caleb Jasik, Krzysztof Maczyński and Alex
Activity
ljharb commentedon Jul 8, 2022
My personal opinion is no. With the current semantics:
With loosened semantics:
The latter seems much worse to me than the former.
theScottyJam commentedon Jul 8, 2022
I would agree here - I would expect to be able to write code like this, and for it to just work:
It would be odd if someone could pass in a then-able and have this function crash because the thenable doesn't implement a
.catch()method.Plus, it's trivial to check if something is a thenable if that's really what's wanted, as you just showed.
Jack-Works commentedon Jul 8, 2022
Maybe we can try to convert a then-able to a Promise.
ljharb commentedon Jul 8, 2022
What would be the benefit? If they want a real promise, they'll Promise.resolve the thenable, or just await it, no?
tabatkins commentedon Jul 11, 2022
Also agree on no - it would be surprising if Promise, alone among the built-ins, accepted random objects that weren't
Promiseobjects.If authors want to handle thenables they can do so themselves. The thenable-handling should be considered a legacy-compatibility thing (we did it to help early adoption, as it gave us compatibility with userland Promise libraries), and not something we care about going forward except for consistency in some cases.
ljharb commentedon Jul 11, 2022
cc @mpcsh @DanielRosenwasser @rkirsling @codehag; any thoughts? If we have consensus on "no" then this can be closed by removing the TODO in the spec.
rkirsling commentedon Jul 11, 2022
I also agree with "no". 👍