-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
awaiting responseIssues waiting for a reply from the OP or another partyIssues waiting for a reply from the OP or another partyenhancement: plugin rule optionNew rule option for an existing eslint-plugin ruleNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
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
Labels
awaiting responseIssues waiting for a reply from the OP or another partyIssues waiting for a reply from the OP or another partyenhancement: plugin rule optionNew rule option for an existing eslint-plugin ruleNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin