Skip to content

Files

Latest commit

 

History

History
35 lines (26 loc) · 629 Bytes

no-thenable.md

File metadata and controls

35 lines (26 loc) · 629 Bytes

Pattern: Object with then method creating thenable

Issue: -

Description

Objects with a then method can be mistakenly treated as promises when used with await, causing unexpected behavior like code after the await never executing.

Examples

Example of incorrect code:

async function example() {
  const foo = {
    unicorn: 1,
    then() {},
  };

  const { unicorn } = await foo;

  console.log("after"); // Never executes
}

Example of correct code:

async function example() {
  const foo = {
    unicorn: 1
  };

  const { unicorn } = foo;
  console.log("after");
}