diff --git a/packages/eslint-plugin/src/rules/no-misused-promises.ts b/packages/eslint-plugin/src/rules/no-misused-promises.ts index 5ef86bff0a8..03b166ec49b 100644 --- a/packages/eslint-plugin/src/rules/no-misused-promises.ts +++ b/packages/eslint-plugin/src/rules/no-misused-promises.ts @@ -537,6 +537,8 @@ function isVoidReturningFunctionType( node: ts.Node, type: ts.Type, ): boolean { + let hadVoidReturn = false; + for (const subType of tsutils.unionTypeParts(type)) { for (const signature of subType.getCallSignatures()) { const returnType = signature.getReturnType(); @@ -547,12 +549,11 @@ function isVoidReturningFunctionType( return false; } - if (tsutils.isTypeFlagSet(returnType, ts.TypeFlags.Void)) { - return true; - } + hadVoidReturn ||= tsutils.isTypeFlagSet(returnType, ts.TypeFlags.Void); } } - return false; + + return hadVoidReturn; } /** diff --git a/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts b/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts index f643f4d91e1..518b7c1d6b5 100644 --- a/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts +++ b/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts @@ -304,6 +304,18 @@ declare const it: ItLike; it('', async () => {}); `, }, + { + code: ` +interface Props { + onEvent: (() => void) | (() => Promise); +} + +declare function Component(props: Props): any; + +const _ = {}} />; + `, + filename: 'react.tsx', + }, ], invalid: [