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
  • Loading branch information
Josh-Cena committed Oct 1, 2023
1 parent 4a6d841 commit 8e75d2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/eslint-plugin/src/rules/no-unsafe-return.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ export default util.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
6 changes: 6 additions & 0 deletions packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ function foo(): Set<number> {
return new Map();
}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/3549
`
function foo(): any {
return [] as any[];
}
`,
],
invalid: [
{
Expand Down

0 comments on commit 8e75d2c

Please sign in to comment.