Skip to content

Commit

Permalink
fix(eslint-plugin): [no-unsafe-return] allow returning anything if ex…
Browse files Browse the repository at this point in the history
…plicitly returning any (#7708)

* fix(eslint-plugin): [no-unsafe-return] allow returning anything if explicitly returning any

* Add test
  • Loading branch information
Josh-Cena committed Oct 19, 2023
1 parent ee4fe89 commit c6124b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/eslint-plugin/src/rules/no-unsafe-return.ts
Expand Up @@ -104,7 +104,13 @@ export default createRule({
// function return type, we shouldn't complain (it's intentional, even if unsafe)
if (functionTSNode.type) {
for (const signature of functionType.getCallSignatures()) {
if (returnNodeType === signature.getReturnType()) {
if (
returnNodeType === signature.getReturnType() ||
util.isTypeFlagSet(
signature.getReturnType(),
ts.TypeFlags.Any | ts.TypeFlags.Unknown,
)
) {
return;
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts
Expand Up @@ -108,6 +108,17 @@ function foo(): Set<number> {
return new Map();
}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/3549
`
function foo(): any {
return [] as any[];
}
`,
`
function foo(): unknown {
return [] as any[];
}
`,
],
invalid: [
{
Expand Down

0 comments on commit c6124b2

Please sign in to comment.