fix(eslint-plugin-react-hooks): accepting `as` expression as a callback (#28202)
## Summary Closes #20750 ## How did you test this change? Added a test case
StyleShit committed
Feb 1, 2024 at 22:08 UTC
2efa38332adc1fc1500753d79fcba41a0197a7a6
2 files changed
+18
packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js
+9
@@ -7765,6 +7765,15 @@ const testsTypescript = {
7765
}
7766
`,
7767
},
7768
+ {
7769
+ code: normalizeIndent`
7770
+ function App(props) {
7771
+ React.useEffect((() => {
7772
+ console.log(props.test);
7773
+ }) as any, [props.test]);
7774
+ }
7775
+ `,
7776
+ },
7777
],
7778
invalid: [
7779
{
packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
+9
@@ -1223,6 +1223,15 @@ export default {
1223
isEffect,
1224
);
1225
return; // Handled
1226
+ case 'TSAsExpression':
1227
+ visitFunctionWithDependencies(
1228
+ callback.expression,
1229
+ declaredDependenciesNode,
1230
+ reactiveHook,
1231
+ reactiveHookName,
1232
+ isEffect,
1233
+ );
1234
+ return; // Handled
1235
case 'Identifier':
1236
if (!declaredDependenciesNode) {
1237
// No deps, no problems.