Bug: Typescript error when import pluginReactHooks from 'eslint-plugin-react-hooks';
React version: without react
Steps To Reproduce
- Clone https://github.com/intsashka/typescript-error-project
- Run
pnpm i - Run
pnpm lint:tsc
Link to code example: https://github.com/intsashka/typescript-error-project
The current behavior
Typescript error:
> [email protected] lint:tsc /Users/intsashka/projects/typescript-error-project
> tsc --noEmit
src/index.ts(8,13): error TS2322: Type '{ meta: { name: string; version: string; }; rules: { 'component-hook-factories': RuleModule; 'exhaustive-deps': { meta: { type: "suggestion"; docs: { description: string; recommended: true; url: string; }; fixable: "code"; hasSuggestions: true; schema: { ...; }[]; }; create(context: RuleContext): { ...; }; }; 'rules...' is not assignable to type 'Plugin'.
Types of property 'configs' are incompatible.
Type '{ recommended: { plugins: string[]; rules: RulesConfig; }; 'recommended-latest': { plugins: string[]; rules: RulesConfig; }; flat: { recommended: ReactHooksFlatConfig; "recommended-latest": ReactHooksFlatConfig; }; }' is not assignable to type 'Record<string, ConfigObject<RulesConfig> | LegacyConfigObject<RulesConfig, RulesConfig> | ConfigObject<RulesConfig>[]>'.
Property 'flat' is incompatible with index signature.
Type '{ recommended: ReactHooksFlatConfig; "recommended-latest": ReactHooksFlatConfig; }' is not assignable to type 'ConfigObject<RulesConfig> | LegacyConfigObject<RulesConfig, RulesConfig> | ConfigObject<RulesConfig>[]'.
ELIFECYCLE Command failed with exit code 2.
The expected behavior
Typescript run without error.
I dug into this a bit. The root cause looks like it's in packages/eslint-plugin-react-hooks/src/index.ts: configs.flat is typed as {recommended: ReactHooksFlatConfig, 'recommended-latest': ReactHooksFlatConfig}, which doesn't satisfy the index signature typescript-eslint's Plugin["configs"] expects (Record<string, ConfigObject | LegacyConfigObject | ConfigObject[]>) — the nested per-key object isn't itself a valid config entry shape.
I'd like to take a shot at fixing this — happy to either (a) give configs.flat its own exported type distinct from the generic Plugin["configs"] constraint, or (b) reshape it to satisfy the existing Plugin type, whichever the maintainers prefer. Let me know if there's a preferred direction, or if someone's already looking into it.
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!