Skip to content

Bug: [no-unsafe-assignment] Differentiate a types-error any from a "true" any #8231

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

Closed
4 tasks done
JoshuaKGoldberg opened this issue Jan 9, 2024 · 3 comments · Fixed by #8304
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@JoshuaKGoldberg
Copy link
Member

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.3.3&fileType=.ts&code=DYUwLgBAbghsCuIBcEB28C2AjEAnA3AFCGwIgQC8EAzgA4D29A1gJ75A&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tieQEMAZolp9kySgHMmAW0Qt0URNGgdokcGAC%2BITUA&tsconfig=&tokens=false

Repro Code

let value: number;

value = spooky;

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-unsafe-assignment": "error"
  }
}

tsconfig

No response

Expected Result

Users should be told that the type is an "error" variant of any. It's confusing to have the same report show up for both a "real" any and an error in type checking.

Actual Result

The same error as if we'd added a declare const spooky: any;:

Unsafe assignment of an `any` value.

Additional Info

Although the type's typeToString() returns "any", its intrinsic name is "error". See the Types panel of the linked playground.

Error types in type checking are often a symptom of misconfiguration around TypeScript and/or typescript-eslint. Example StackOverflow question around an any in a lint rule.

@JoshuaKGoldberg JoshuaKGoldberg added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jan 9, 2024
@bradzacher
Copy link
Member

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages%2Ftype-utils%2Fsrc%2Fpredicates.ts#L88-L96

We already have some handling for this - though not every callsite uses that util..

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Feb 4, 2024
@JoshuaKGoldberg JoshuaKGoldberg changed the title Bug: [no-redundant-type-constituents, no-unsafe-*] Differentiate a types-error any from a "true" any Bug: [no-unsafe-assignment] Differentiate a types-error any from a "true" any Jun 3, 2024
@JoshuaKGoldberg
Copy link
Member Author

JoshuaKGoldberg commented Jun 3, 2024

Since #8304 is 1 approval, retargeting this issue to just be for no-unsafe-assignment. I'll file separate issues for the other rules that it impacts.

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 locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants