This rule raises an issue when an object, class, or module defines a property or method named then.

Why is this an issue?

JavaScript treats an object as "thenable" when its then property is callable, like a Promise. This can cause unexpected behavior in await expressions or dynamic imports.

An await expression uses Promise resolution to read the object’s then property. If the value is callable, resolution calls it as a thenable method. This can lead to:

The same issue occurs with dynamic imports. If a module exports a then function, the import statement will treat the entire module as thenable, potentially calling the then function instead of returning the module object.

This behavior follows JavaScript’s Promise resolution algorithm, which checks whether the then value is callable.

In production, this can leave user interfaces unresponsive or data processing incomplete. Because the symptoms can appear far from the then property, they can also make failures hard to debug.

How to fix it

Rename the then property to a more descriptive name that reflects its actual purpose.

Code examples

Noncompliant code example

const userAction = {
  userId: 123,
  then() { // Noncompliant
    console.log('Action completed');
  }
};

Compliant solution

const userAction = {
  userId: 123,
  complete() {
    console.log('Action completed');
  }
};

Exceptions

The rule does not raise an issue when then is used as part of a JSON Schema conditional validation construct alongside an if property. In JSON Schema, if/then/else are standard keywords for conditional schema application and do not create thenable behavior.

const schema = {
  if: { properties: { age: { minimum: 18 } } },
  then: { required: ['driversLicense'] }, // Compliant - JSON Schema conditional
  else: { required: ['parentConsent'] },
};

No issue will be raised when then is used as a type reference (assigning the Function constructor as a value) in an interface shape descriptor. This pattern describes the expected interface shape of an object, not a method creating thenable behavior.

const connectionInterface = {
  open: Function,
  send: Function,
  then: Function, // Compliant - interface shape descriptor
  close: Function,
};

No issue will be raised when a then property is inside an object that also has an is property and the project uses a validation library such as Yup or Joi. This {is, then} pattern is recognized as a conditional validation configuration used by methods like .when() and .conditional() in these libraries.

import * as yup from 'yup';

const schema = yup.string().when('hasName', {
  is: true,
  then: (schema) => schema.required(), // Compliant: conditional validation config
});

const formSchema = yup.object().shape({
  parentalConsent: yup.bool().when('age', {
    is: (age) => age < 18,
    then: (schema) => schema.required(), // Compliant: conditional validation config
  }),
});
import Joi from 'joi';

const schema = Joi.string().when('type', {
  is: 'email',
  then: Joi.string().email().required(), // Compliant: conditional validation config
});

The rule ignores a numeric then property in a Gherkin indentation map when the file imports @cucumber/gherkin at runtime. Type-only imports do not qualify, but side-effect imports do. The map must be an object literal used directly as the initializer of a const variable. TypeScript annotations and assertions around the literal or its values do not affect the exception. Aliases and runtime wrappers such as Object.freeze() do not qualify. The map must define the Feature, given, when, and then keys. Fixed computed keyword names count as keys. Every static property value must be an unsigned numeric literal.

import '@cucumber/gherkin';

const indentation: Readonly<Record<string, number>> = {
  Feature: 0 as const,
  given: 2,
  when: 2,
  then: 2 satisfies number, // Compliant: Gherkin indentation data
};

const thenable = {
  Feature: 0,
  given: 2,
  when: 2,
  then() {}, // Noncompliant: callable `then` makes this object thenable
};

A spread or computed key before then does not by itself prevent this exception because an explicit numeric then property replaces any earlier then value. A spread, unknown computed key, or another then property after it prevents the exception because it can replace that value. The rule can report numeric then properties outside this Gherkin map pattern.

No issue will be raised on a class’s non-static then member (method or field) when that same class declares an explicit thenable contract, either via a JSDoc @implements tag or a TypeScript implements clause naming IThenable, Thenable, or PromiseLike (with or without type arguments). This documents an intentional Promise-like implementation rather than an accidental thenable.

/**
 * @implements {IThenable<string>}
 */
class Task {
  then(onFulfilled) { // Compliant: class declares an explicit thenable contract
    return onFulfilled('done');
  }
}
class Task implements PromiseLike<string> {
  private readonly promise = Promise.resolve('done');

  then<TResult1 = string, TResult2 = never>( // Compliant: class declares an explicit thenable contract
    onFulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | null,
    onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null,
  ): PromiseLike<TResult1 | TResult2> {
    return this.promise.then(onFulfilled, onRejected);
  }
}

This exception applies to the nearest enclosing class only, and does not extend to static then members: implements/@implements describes the instance shape, not the class object itself, which can still be treated as thenable (e.g. by a dynamic import).

The contract is recognized by name: the rule takes the declaration at face value and does not check that the named type is genuinely Promise-compatible. Only annotate a class this way when its then really does honor Promise semantics.

interface Thenable {
  then(onFulfilled: (value: string) => void): void;
}

class Row implements Thenable {
  private readonly pending: ((value: string) => void)[] = [];

  then(onFulfilled: (value: string) => void) { // No issue raised, but `await row` never settles
    this.pending.push(onFulfilled); // queued, never invoked
  }
}

If the rule flags a then you believe is safe, inspect its final value. A non-callable value cannot create thenable behavior, so the finding can be a false positive even if Promise resolution receives the object. For a callable or unknown value, treat the finding as a false positive only if the object cannot reach any Promise resolution path. Examples include await, dynamic import(), Promise.resolve(), and resolving a Promise with the object. Otherwise, rename an accidental callable then, or implement the Promise contract when thenable behavior is intentional.

Resources

Documentation