diff --git a/packages/eslint-plugin/src/rules/no-unsafe-return.ts b/packages/eslint-plugin/src/rules/no-unsafe-return.ts index fa301bafa65..ef308450bd8 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-return.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-return.ts @@ -104,7 +104,7 @@ export default createRule({ // If there is an explicit type annotation *and* that type matches the actual // function return type, we shouldn't complain (it's intentional, even if unsafe) if (functionTSNode.type) { - for (const signature of functionType.getCallSignatures()) { + for (const signature of tsutils.getCallSignaturesOfType(functionType)) { if ( returnNodeType === signature.getReturnType() || isTypeFlagSet( diff --git a/packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts b/packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts index 42a798ffe11..36c6103bbc2 100644 --- a/packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts @@ -45,6 +45,14 @@ function foo() { function foo(): any { return {} as any; } + `, + ` +declare function foo(arg: () => any): void; +foo((): any => 'foo' as any); + `, + ` +declare function foo(arg: null | (() => any)): void; +foo((): any => 'foo' as any); `, // explicit any array return type is allowed, if you want to be unsafe like that ` @@ -408,5 +416,19 @@ function bar() { }, ], }, + { + code: ` +declare function foo(arg: null | (() => any)): void; +foo(() => 'foo' as any); + `, + errors: [ + { + messageId: 'unsafeReturn', + line: 3, + column: 11, + endColumn: 23, + }, + ], + }, ], });