Search code examples
javascriptpromisees6-promise

JS Promises: does the then() method always return a promise, or can it return a thenable?


I'm reading this article about Promise chaining, and it says "a handler may return not exactly a promise, but a so-called “thenable” object". I want to know which of the following is correct:

1) The handler can return a promise or a then-able object, but the then() method containing the handler must return a promise.

2) The handler can return a promise or a then-able object, and the then() method containing the handler can also return either a promise or a then-able object.


Solution

  • It's not a promise unless its .then(…) method returns a promise, and if it's an ES6 native Promise then it definitely will.

    A thenable's then method may return anything (including undefined).