Skip to content

Fix TypeScript typing for flat config in eslint-plugin-react-hooks#694

Open
everettbu wants to merge 1 commit intomainfrom
fix-react-hooks-flat-config-types
Open

Fix TypeScript typing for flat config in eslint-plugin-react-hooks#694
everettbu wants to merge 1 commit intomainfrom
fix-react-hooks-flat-config-types

Conversation

@everettbu
Copy link
Copy Markdown

Mirror of facebook/react#36017
Original author: anasahhm


Fixes #36016

The ReactHooksFlatConfig type defined the plugins property as { react: any },
while the actual runtime configuration uses the key 'react-hooks'.

This mismatch causes incorrect TypeScript inference when using
configs.flat.recommended in ESLint flat configuration with TypeScript strict mode.

This change updates the ReactHooksFlatConfig type so that the plugins
property correctly reflects the plugin key 'react-hooks'.

No runtime behaviour is changed.
This is a type-only correction to align
the TypeScript definition with the actual configuration object.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 12, 2026

Greptile Summary

This PR is a type-only correction to eslint-plugin-react-hooks that fixes a mismatch between the ReactHooksFlatConfig TypeScript type and the actual runtime flat config object. The plugins property key was incorrectly typed as react when the real key used at runtime is 'react-hooks', causing incorrect inference under TypeScript strict mode. The fix also improves the value type from any to unknown, and adds as const to the legacy string-array plugins constant for tighter inference.

  • Renames the plugins property key in ReactHooksFlatConfig from react'react-hooks' to match the actual config object shape
  • Upgrades the plugin value type from any to unknown, removing an implicit escape hatch from TypeScript checking
  • Adds as const to const plugins = ['react-hooks'], making the array a readonly tuple for more precise typing
  • Minor style-only formatting adjustments (spaces inside braces, added blank line)

Confidence Score: 5/5

  • This PR is safe to merge — it is a purely additive type-only correction with zero runtime impact.
  • The change touches only a TypeScript type definition and two cosmetic style adjustments. No executable code path is altered. The fix correctly aligns the declared type with the actual runtime object shape ('react-hooks' key), and the unknown substitution for any is strictly more correct. No edge cases, no new dependencies, no API surface changes.
  • No files require special attention.

Important Files Changed

Filename Overview
packages/eslint-plugin-react-hooks/src/index.ts Type-only fix: corrects ReactHooksFlatConfig.plugins key from react to 'react-hooks', changes the value type from any to unknown, and adds as const to the legacy plugins array. No runtime behaviour changes.

Last reviewed commit: 621ea1c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants