-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
fix(eslint-plugin): [no-unnecessary-type-assertion] handle literal types #10523
base: main
Are you sure you want to change the base?
fix(eslint-plugin): [no-unnecessary-type-assertion] handle literal types #10523
Conversation
Thanks for the PR, @mdm317! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
View your CI Pipeline Execution ↗ for commit 4c45f10.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10523 +/- ##
=======================================
Coverage 86.90% 86.90%
=======================================
Files 446 446
Lines 15502 15504 +2
Branches 4516 4517 +1
=======================================
+ Hits 13472 13474 +2
Misses 1675 1675
Partials 355 355
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just requesting changes on naming and removing the noFormat
. Thanks!
@@ -358,6 +358,16 @@ if (Math.random()) { | |||
x!; | |||
`, | |||
}, | |||
"let a = (Date.now() % 2 ? 'a' : 'b') as 'a' | 'b';", | |||
noFormat` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Style] The added doesn't involve formatting/layout nuance, so there's no need to noFormat
in them:
noFormat` | |
` |
const wouldSameTypeBeInferred = castType.isLiteral() | ||
? isImplicitlyNarrowedConstDeclaration(node) | ||
: !isConstAssertion(node.typeAnnotation); | ||
const isCastTypeTemplateLiteral = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Docs] #10472
const isCastTypeTemplateLiteral = | |
const isAssertionTypeTemplateLiteral = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! Just requesting minor changes around testing 🏆
Edit: I'm not sure if it's too fringe, but I did see one regression with the readonly
modifier (main branch playground link, deploy preview playground link).
|
||
const wouldSameTypeBeInferred = | ||
castType.isLiteral() || | ||
isAssertionTypeTemplateLiteral || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Testing]: No tests fail if this is omitted (isAssertionTypeTemplateLiteral ||
), let's simplify or add a test case?
PR Checklist
Overview
Add case when cast type is a template literal or a union type that is string-like.