Skip to content

[eslint-plugin-react-hooks] Skip TSQualifiedName chains inside typeof#36300

Open
ousamabenyounes wants to merge 1 commit intofacebook:mainfrom
ousamabenyounes:fix/issue-27335
Open

[eslint-plugin-react-hooks] Skip TSQualifiedName chains inside typeof#36300
ousamabenyounes wants to merge 1 commit intofacebook:mainfrom
ousamabenyounes:fix/issue-27335

Conversation

@ousamabenyounes
Copy link
Copy Markdown

Summary

Fixes #27335.

exhaustive-deps skipped references whose parent was a TSTypeQuery (e.g. typeof foo) or TSTypeReference (e.g. Foo). That correctly handled direct usage, but nested type paths like typeof foo.bar slipped through: in the AST the root identifier's parent is a TSQualifiedName, not the outer TSTypeQuery, so the reference was recorded as a missing dependency.

function Dummy() {
  const [foo, setFoo] = useState<{bar: number}>({bar: 42});
  useEffect(() => {
    const square = (x: typeof foo.bar) => x * x;
    setFoo(previous => ({...previous, bar: square(previous.bar)}));
  }, []);
  //  ^ before: "React Hook useEffect has a missing dependency: 'foo'."
  //    after:  no lint error — `typeof foo.bar` is purely type-level.
}

Walking up through TSQualifiedName before checking the ancestor kind covers arbitrary-depth chains (typeof a.b.c, etc.).

How did you test this change?

Added a regression case to ESLintRuleExhaustiveDeps-test.js exercising the exact repro from the issue.

  • ESLintRuleExhaustiveDeps-test.js: 3652 passed / 0 failed (3644 baseline + new case × 2 ESLint versions × 4 parser configs).
  • ESLintRulesOfHooks-test.js: 1420 passed / 0 failed (unaffected, verified).
  • yarn flow dom-node — clean.
  • yarn linc — clean.
  • yarn prettier — clean.

🤖 Generated with Claude Code

`exhaustive-deps` skipped references whose parent was a `TSTypeQuery`
or `TSTypeReference`, which correctly handled `typeof foo` / `Foo` but
not nested access like `typeof foo.bar` — there the root identifier's
parent is a `TSQualifiedName`, not the outer `TSTypeQuery`, so the
reference slipped through and was reported as a missing dependency.

Walk up through any `TSQualifiedName` nodes before checking the
ancestor kind, so `typeof foo.bar.baz` and similar chains are now
also treated as purely type-level references (fixes facebook#27335).

Co-Authored-By: Claude <noreply@anthropic.com>
@meta-cla meta-cla bot added the CLA Signed label Apr 17, 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: Incorrect dependency requirement when using typeof on nested data structures

1 participant