Skip to content

Enhancement: [no-explicit-any] Add option to allow any in satisfies operator #11522

@adamalfredsson

Description

@adamalfredsson

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-explicit-any/

Description

Current Behavior

The @typescript-eslint/no-explicit-any rule currently flags all uses of any, including when used within the satisfies operator. This creates friction when using satisfies for type checking where the specific types are intentionally flexible or complex.

Desired Behavior

Add a new option to the no-explicit-any rule to allow any when used specifically within satisfies expressions.

Use Case

The satisfies operator is often used to ensure a value conforms to a general shape without requiring exact type parameters. For example:

type Routes = '/home' | '/about' | '/contact';

const routeConfig = {
  '/home': { component: HomeComponent, requiresAuth: false },
  '/about': { component: AboutComponent, requiresAuth: false },
  '/contact': { component: ContactComponent, requiresAuth: true },
} satisfies Record<Routes, any>;

In these cases:

  • The actual types are correctly inferred from the values
  • The satisfies clause only validates the general shape
  • Using unknown doesn't work due to type constraints
  • Specifying exact types would be redundant and harder to maintain

Proposed Solution

Add a new option to the rule configuration:

type Options = {
  ignoreRestArgs?: boolean;
  fixToUnknown?: boolean;
  allowInSatisfies?: boolean; // New option
}

Usage:

{
  "rules": {
    "@typescript-eslint/no-explicit-any": ["error", {
      "allowInSatisfies": true
    }]
  }
}

Fail

type Routes = '/home' | '/about' | '/contact';

const routeConfig = {
  '/home': { component: HomeComponent, requiresAuth: false },
  '/about': { component: AboutComponent, requiresAuth: false },
  '/contact': { component: ContactComponent, requiresAuth: true },
} as Record<Routes, any>;

Pass

type Routes = '/home' | '/about' | '/contact';

const routeConfig = {
  '/home': { component: HomeComponent, requiresAuth: false },
  '/about': { component: AboutComponent, requiresAuth: false },
  '/contact': { component: ContactComponent, requiresAuth: true },
} satisfies Record<Routes, any>;

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting responseIssues waiting for a reply from the OP or another partyenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions