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-unnecessary-type-assertion] errors not reported when using unnecessary literal assertions on const variable declarations #8566

Closed
4 tasks done
abrahamguo opened this issue Feb 27, 2024 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@abrahamguo
Copy link
Contributor

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#eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWkOTJE0fJQ5N0UOdA7RI4MAF8QOoA&code=MYewdgzgLgBAZiEMC8MA8BmAfBg3EA

Repro Code

const foo = <3>3;

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unnecessary-type-assertion": "error"
  },
};

tsconfig

{}

Expected Result

3 should be reported as an unnecessary type assertion, since removing it has no effect.

Actual Result

The type assertion was not reported.

Additional Info

Raised originally in #8458 and solution opened in #8558. Breaking this out from the original issue into a separate issue.

@abrahamguo abrahamguo 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 Feb 27, 2024
@auvred
Copy link
Member

auvred commented Feb 27, 2024

Look like a duplicate of #4485

@bradzacher
Copy link
Member

This is working as intended.

Its not always safe to remove an assertion to a literal type as there are cases where TS will widen the type - so the rule ignores assertions to literal types (and tuple types).

example widening case.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look labels Feb 27, 2024
@bradzacher
Copy link
Member

100% right @auvred - duplicate of #4485

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
@bradzacher bradzacher added duplicate This issue or pull request already exists and removed awaiting response Issues waiting for a reply from the OP or another party labels Feb 27, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants