Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 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,17 @@ function foo(): Set<number> {
return new Map();
}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/3549
`
function foo(): any {
return [] as any[];
}
`,
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Testing] Could you add a test for unknown too?

some room for interpretation.

Yeah I think this is fine as-is for now. If folks really give solid use-cases for the more complex ones we can always look into adding more complexity.

`
function foo(): unknown {
return [] as any[];
}
`,
],
invalid: [
{
Expand Down