Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: Type incompatibility with fixupPluginRules() from @eslint/compat #9115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
karlhorky opened this issue May 18, 2024 · 3 comments
Closed
4 tasks done
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. working as intended Issues that are closed as they are working as intended

Comments

@karlhorky
Copy link

karlhorky commented May 18, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

utils

Playground Link

No response

Repro Code

import { fixupPluginRules } from '@eslint/compat';
import react from 'eslint-plugin-react';

/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigArray} */
const configArray = [
  {
    plugins: {
      react: fixupPluginRules(react), // 💥 Type 'FixupPluginDefinition' is not assignable to type 'Omit<Plugin, "configs">'.
                                      //   Types of property 'rules' are incompatible.
                                      //    Type 'Record<string, FixupRuleDefinition> | undefined' is not assignable to type 'Record<string, LooseRuleDefinition> | undefined'.
                                      //      Type 'Record<string, FixupRuleDefinition>' is not assignable to type 'Record<string, LooseRuleDefinition>'.
                                      //        'string' index signatures are incompatible.
                                      //          Type 'FixupRuleDefinition' is not assignable to type 'LooseRuleDefinition'.ts(2322)
    },
  },
];

ESLint Config

See above

tsconfig

n/a

Expected Result

The types for SharedConfig.RuleEntry match the return type for fixupPluginRules() from @eslint/compat

Actual Result

The types do not match:

Type 'FixupPluginDefinition' is not assignable to type 'Omit<Plugin, "configs">'.
  Types of property 'rules' are incompatible.
    Type 'Record<string, FixupRuleDefinition> | undefined' is not assignable to type 'Record<string, LooseRuleDefinition> | undefined'.
      Type 'Record<string, FixupRuleDefinition>' is not assignable to type 'Record<string, LooseRuleDefinition>'.
        'string' index signatures are incompatible.
          Type 'FixupRuleDefinition' is not assignable to type 'LooseRuleDefinition'.ts(2322)

Additional Info

No response

Versions

package version
@typescript-eslint/eslint-plugin 7.9.1-alpha.6
@typescript-eslint/parser 7.9.1-alpha.6
@typescript-eslint/rule-tester 7.9.1-alpha.6
@typescript-eslint/scope-manager 7.9.1-alpha.6
@typescript-eslint/typescript-estree 7.9.1-alpha.6
@typescript-eslint/type-utils 7.9.1-alpha.6
@typescript-eslint/utils 7.9.1-alpha.6
TypeScript 5.4.5
ESLint 9.3.0
node 20.13.1

I also tried the latest v8 alpha (@typescript-eslint/[email protected]), which should be compatible with ESLint v9, but this also results in the same error.

@karlhorky karlhorky added bug Something isn't working triage Waiting for team members to take a look labels May 18, 2024
@bradzacher
Copy link
Member

bradzacher commented May 18, 2024

Wow they committed the cardinal sin of using Object.

https://github.com/eslint/rewrite/blob/d5a04961b99e4e3e529d631089a51b68581bb741/packages/compat/src/types.ts#L13-L15

Honestly I think that this is a bug in their types, not ours. You'll find that their types also don't work with @types/eslint.

They've ultimately defined these super loose janky types that nobody can align with.

We already define super loose types for this assignment to be permissive and accept many things - but they're even looser than we are which is insane to consider.

export type LooseRuleDefinition =
// TODO - ESLint v9 will remove support for RuleCreateFunction
| LooseRuleCreateFunction
| {
meta?: object | undefined;
create: LooseRuleCreateFunction;
};
/*
eslint-disable-next-line @typescript-eslint/no-explicit-any --
intentionally using `any` to allow bi-directional assignment (unknown and
never only allow unidirectional)
*/
export type LooseRuleCreateFunction = (context: any) => Record<
string,
/*
eslint-disable-next-line @typescript-eslint/ban-types --
intentionally use Function here to give us the basic "is a function" validation
without enforcing specific argument types so that different AST types can still
be passed to configs
*/
Function | undefined
>;

So yeah I'd file an issue upstream and get them to define something that'll work with the existing ecosystem.

((separately they should consider using our recommended rule set on their TS files to catch such issues))

@bradzacher bradzacher added wontfix This will not be worked on external This issue is with another package, not typescript-eslint itself awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look wontfix This will not be worked on labels May 18, 2024
@karlhorky
Copy link
Author

karlhorky commented May 19, 2024

Good point, thanks! I also was able to confirm that the @eslint/compat types are incompatible with the Linter.FlatConfig[] type from @types/eslint.

I reported it over here:

@bradzacher
Copy link
Member

I'll close this out then as there's nothing for us to action from our side.

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2024
@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended and removed awaiting response Issues waiting for a reply from the OP or another party labels May 19, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2024
@bradzacher bradzacher added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

2 participants