gkeenley
gkeenley

Reputation: 7388

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.

Upvotes: 2

Views: 296

Answers (1)

Bergi
Bergi

Reputation: 664920

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).

Upvotes: 1

Related Questions