Promise.allSettled() - why string?

# Felipe Gasper (5 years ago)

Hello,

If it’s not too awkward of a question to ask: were object methods rather than string comparison considered for Promise.allSettled()?

For example, if I write this:


Promise.allSettled(promises).then( results => { results.forEach( r => { if (r.status === "rejectd") { // Failure … } else { // Success! } } ); } );

… the code won’t complain about the typo but instead just “do the wrong thing”.

But, if the way to parse allSettled()’s resolution were object methods instead, it could be this:


Promise.allSettled(promises).then( results => { results.forEach( r => { if (r.isRejectd()) { // Failure … } else { // Success! } } ); } );

… which will usefully cause an exception/rejection that pinpoints the problem in my code.

Was this pattern perhaps considered and rejected? Or is there some liability to the object methods relative to the string comparison that I’m not seeing? If so, what was/is the rationale there?

Thank you for your time!
# Jordan Harband (5 years ago)

The iteration protocol has a boolean data property .done - I don't know if anyone ever suggested some kind of isDone() method for that, and I think the iteration protocol sets a precedent of the "tag" on the object being a primitive.