Skip to content

Commit 7f4381f

Browse files
committed
Fix exhaustive deps bug with flow type casting. (#35691)
Summary: I noticed there's a bug where the lint will recognize the type on a cast annotation as a missing dependency; ``` function MyComponent() { type ColumnKey = 'id' | 'name'; type Item = {id: string, name: string}; const columns = useMemo( () => [ { type: 'text', key: 'id', } as TextColumn<ColumnKey, Item>, ^^^^^^^^ here ], [], ); } ``` This is due to the AST of AsExpressions being something like: AsExpression └── typeAnnotation: GenericTypeAnnotation └── typeParameters: TypeParameterInstantiation └── params[0]: GenericTypeAnnotation └── id: Identifier (name: "ColumnKey") Where `ColumnKey` never has a TypeParameter Annotation. So we need to consider it to be a flow type due to it belonging to a GenericTypeAnnotation Test Plan: Added unit tests Before: ``` Test Suites: 1 failed, 2 passed, 3 total Tests: 2 failed, 5065 passed, 5067 total Snapshots: 0 total Time: 16.517 s Ran all test suites. error Command failed with exit code 1. ``` After: ``` PASS __tests__/ReactCompilerRuleTypescript-test.ts PASS __tests__/ESLintRulesOfHooks-test.js (6.192 s) PASS __tests__/ESLintRuleExhaustiveDeps-test.js (9.97 s) Test Suites: 3 passed, 3 total Tests: 5067 passed, 5067 total Snapshots: 0 total Time: 10.21 s, estimated 11 s Ran all test suites. ✨ Done in 12.66s. ``` DiffTrain build for [c137dd6](c137dd6)
1 parent 9a57813 commit 7f4381f

35 files changed

+90
-89
lines changed

compiled/eslint-plugin-react-hooks/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ const rule$1 = {
340340
const optionalChains = new Map();
341341
gatherDependenciesRecursively(scope);
342342
function gatherDependenciesRecursively(currentScope) {
343-
var _a, _b, _c, _d, _e;
343+
var _a, _b, _c, _d, _e, _f;
344344
for (const reference of currentScope.references) {
345345
if (!reference.resolved) {
346346
continue;
@@ -378,7 +378,8 @@ const rule$1 = {
378378
if (def.node != null && def.node.init === node.parent) {
379379
continue;
380380
}
381-
if (def.type === 'TypeParameter') {
381+
if (def.type === 'TypeParameter' ||
382+
((_e = dependencyNode.parent) === null || _e === void 0 ? void 0 : _e.type) === 'GenericTypeAnnotation') {
382383
continue;
383384
}
384385
if (!dependencies.has(dependency)) {
@@ -391,7 +392,7 @@ const rule$1 = {
391392
});
392393
}
393394
else {
394-
(_e = dependencies.get(dependency)) === null || _e === void 0 ? void 0 : _e.references.push(reference);
395+
(_f = dependencies.get(dependency)) === null || _f === void 0 ? void 0 : _f.references.push(reference);
395396
}
396397
}
397398
for (const childScope of currentScope.childScopes) {

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22a20e1f2f557b99115d82b639ff5a32b6453cb6
1+
c137dd6f5484f1bb68a64f07dd0e40d474a29759
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22a20e1f2f557b99115d82b639ff5a32b6453cb6
1+
c137dd6f5484f1bb68a64f07dd0e40d474a29759

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ __DEV__ &&
14821482
exports.useTransition = function () {
14831483
return resolveDispatcher().useTransition();
14841484
};
1485-
exports.version = "19.3.0-www-classic-22a20e1f-20260204";
1485+
exports.version = "19.3.0-www-classic-c137dd6f-20260204";
14861486
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14871487
"function" ===
14881488
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ __DEV__ &&
14821482
exports.useTransition = function () {
14831483
return resolveDispatcher().useTransition();
14841484
};
1485-
exports.version = "19.3.0-www-modern-22a20e1f-20260204";
1485+
exports.version = "19.3.0-www-modern-c137dd6f-20260204";
14861486
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14871487
"function" ===
14881488
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.3.0-www-classic-22a20e1f-20260204";
613+
exports.version = "19.3.0-www-classic-c137dd6f-20260204";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.3.0-www-modern-22a20e1f-20260204";
613+
exports.version = "19.3.0-www-modern-c137dd6f-20260204";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.3.0-www-classic-22a20e1f-20260204";
617+
exports.version = "19.3.0-www-classic-c137dd6f-20260204";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.3.0-www-modern-22a20e1f-20260204";
617+
exports.version = "19.3.0-www-modern-c137dd6f-20260204";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20375,10 +20375,10 @@ __DEV__ &&
2037520375
(function () {
2037620376
var internals = {
2037720377
bundleType: 1,
20378-
version: "19.3.0-www-classic-22a20e1f-20260204",
20378+
version: "19.3.0-www-classic-c137dd6f-20260204",
2037920379
rendererPackageName: "react-art",
2038020380
currentDispatcherRef: ReactSharedInternals,
20381-
reconcilerVersion: "19.3.0-www-classic-22a20e1f-20260204"
20381+
reconcilerVersion: "19.3.0-www-classic-c137dd6f-20260204"
2038220382
};
2038320383
internals.overrideHookState = overrideHookState;
2038420384
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -20413,7 +20413,7 @@ __DEV__ &&
2041320413
exports.Shape = Shape;
2041420414
exports.Surface = Surface;
2041520415
exports.Text = Text;
20416-
exports.version = "19.3.0-www-classic-22a20e1f-20260204";
20416+
exports.version = "19.3.0-www-classic-c137dd6f-20260204";
2041720417
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2041820418
"function" ===
2041920419
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)