Skip to content

Commit c6124b2

Browse files
authored
fix(eslint-plugin): [no-unsafe-return] allow returning anything if explicitly returning any (#7708)
* fix(eslint-plugin): [no-unsafe-return] allow returning anything if explicitly returning any * Add test
1 parent ee4fe89 commit c6124b2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/eslint-plugin/src/rules/no-unsafe-return.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,13 @@ export default createRule({
104104
// function return type, we shouldn't complain (it's intentional, even if unsafe)
105105
if (functionTSNode.type) {
106106
for (const signature of functionType.getCallSignatures()) {
107-
if (returnNodeType === signature.getReturnType()) {
107+
if (
108+
returnNodeType === signature.getReturnType() ||
109+
util.isTypeFlagSet(
110+
signature.getReturnType(),
111+
ts.TypeFlags.Any | ts.TypeFlags.Unknown,
112+
)
113+
) {
108114
return;
109115
}
110116
}

packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ function foo(): Set<number> {
108108
return new Map();
109109
}
110110
`,
111+
// https://github.com/typescript-eslint/typescript-eslint/issues/3549
112+
`
113+
function foo(): any {
114+
return [] as any[];
115+
}
116+
`,
117+
`
118+
function foo(): unknown {
119+
return [] as any[];
120+
}
121+
`,
111122
],
112123
invalid: [
113124
{

0 commit comments

Comments
 (0)