Skip to content

fix(eslint-plugin-react-hooks): fix configs.flat properties typed as undefined in strict mode#36273

Open
abhishekayu wants to merge 1 commit intofacebook:mainfrom
abhishekayu:fix/36016-eslint-plugin-react-hooks-ts-types
Open

fix(eslint-plugin-react-hooks): fix configs.flat properties typed as undefined in strict mode#36273
abhishekayu wants to merge 1 commit intofacebook:mainfrom
abhishekayu:fix/36016-eslint-plugin-react-hooks-ts-types

Conversation

@abhishekayu
Copy link
Copy Markdown

Fixes #36016

Summary

When using eslint-plugin-react-hooks with TypeScript strict mode, accessing configs.flat.recommended in eslint.config.ts throws:

The issue is that configs.flat was initialized as an empty object {} with a type cast. TypeScript doesn't know the properties exist until Object.assign runs later, so it treats them as possibly undefined in strict mode.

Two small changes to fix this:

  • Use null as unknown as {...} instead of {} as {...} for the initial declaration
  • Replace Object.assign(configs.flat, {...}) with a direct assignment configs.flat = {...}

Runtime behavior is identical - only the types change.

How did you test this change?

Checked that configs.flat.recommended and configs.flat['recommended-latest'] are no longer inferred as T | undefined in strict mode.

This now works without needing !:

import reactHooks from 'eslint-plugin-react-hooks';

export default [
  reactHooks.configs.flat.recommended, // no type error
];

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Apr 15, 2026

Hi @abhishekayu!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Apr 15, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed label Apr 15, 2026
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.

Bug: eslint-plugin-react-hooks Typescript types are broken

1 participant