-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [no-unnecessary-type-assertion] does not detect unnecessary non-null-assertion on a call expression #8141
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
Comments
This is most likely a bug, when asserting typescript-eslint/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts Line 172 in cde4d4d
(because as far I know typescript-eslint/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts Lines 99 to 103 in cde4d4d
I think it's fine to file a separate issue about this, as it's not related to non-null assertions bug |
Why is this a bad fix? You need to run your formatter after autofixing; ESLint does not care about formatting and it's explicitly an antipattern for ESLint autofixers to conform to your formatting patterns. |
This is not correct. When you inspect the type of a call expression - you are inspecting the return type of the call. For example if you look at the types tab in the playground and select the call expression - you will see it's type is |
@Josh-Cena i 100% agree with you! Though in this case it does appear to be an off-by-one error. It's also done in a really dodgy way - by using "sketchy math" and assuming a specific code shape. We should really just be removing the Tangent aside - I too am fine with us leaving this as is and assuming another rule will pickup the formatting, as is standard and expected in the ESLint ecosystem. |
I think it's because this rule ignores everything that doesn't have a declaration, thinking they may be "use before define"? const a = (1 + 1)!;
const a = new Date()!; |
Thanks for your opinion. typescript-eslint/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts Lines 266 to 282 in cde4d4d
|
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/rules/no-unnecessary-type-assertion
Description
I propose that the
no-unnecessary-type-assertion
rule should also check for the return type of a function.Fail
Pass
Additional Info
Im ready to send a PR after the issue is marked with the
accepting prs
label as indicated on the PR Checklist. Welcome to provide more test cases.The text was updated successfully, but these errors were encountered: