Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: [no-unsafe-return] any to any callback is not allowed when cb is union type #8982

Closed
4 tasks done
HolgerJeromin opened this issue Apr 24, 2024 · 1 comment · Fixed by #9001
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@HolgerJeromin
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.1.6&fileType=.ts&code=CYUwxgNghgTiAEAzArgOzAFwJYHtXwxilQGdEcYBbAQVQE8BhAIwAowmAueFl4KDKF2J0AlPAC8APnjCRIofQDcAWABQhYmQo16zHnwELRRidIDea%2BPDgZkMfAaiKrAehfwA8gGk1AXxEqqmqgkLAIKOjYeAREpORUtIxMHjAAcsgQEGyc8KgZEPAAPty8-IIy9GJSFaLyNYEacdqJzCnpmfplRnXCpvBm8JbWILb28I7ObvAAqqRQiAg2dvg4iBXwAAbCGwR0AA4gwPAAblAQyCAAdH4BakA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tieQEMAZolrRE%2BWNCbpIiaNA7RI4MAF8QKoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A&tokens=true

Repro Code

declare function transformAnyCb(cb: ((data: any) => any)): any;
transformAnyCb((data: any): any => {
  return data;  // OK
});

declare function transformAnyCbOrNull(cb: null | ((data: any) => any)): any;
transformAnyCbOrNull((data: any): any => { 
  return data; // Unsafe return of an `any` typed value.
});

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unsafe-return":"error"
  },
};

tsconfig

{
  "compilerOptions": {
    "strict": true
  }
}

Expected Result

I typed the callback to allow any as a return value. So the any to any converter should be fine.

Actual Result

ts-eslint is unhappy with

Unsafe return of an any typed value.

Additional Info

No response

@HolgerJeromin HolgerJeromin added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Apr 24, 2024
@kirkwaiblinger kirkwaiblinger added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Apr 26, 2024
@kirkwaiblinger
Copy link
Member

@HolgerJeromin Thanks for the report! 🙂 Agreed that this is a bug. When any is explicitly specified as a return type, the rule should allow any to be returned!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants