-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [no-unnecessary-type-assertion] False report with an 'as' assertion #10257
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 because |
But then it's not an unnecessary type assertion either. I mean you can use the type assertion I mean the error is a little bit misleading as the Either the error should be removed or the |
Alternatively you can use |
Here is a more minimal example: |
Noting that this is closely related to #8721 |
Reopening since we reverted #10523. |
I have a similar bug, and I'm not sure if it's the same as this one or a different one because, differently from the one in this PR, changing function fn(w: "a" | "b") {
const pattern = `${w}` as `${typeof w}`;
return pattern;
}
// If you remove the "unnecessary assertion" above, this errors
let res: "a" | "b" = fn("a"); EDIT: This is exactly the same as the one in this issue, and replacing |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.6.2&fileType=.tsx&code=MYewdgzgLgBNCGUCmAuGAiJAPADgSwCckATdGAHwxyTGLzAHMyBeKmux9AbgCgeAzAK5hgUPOBgBbePQAUAShgBvHjBhEoggmGWq1MKAE9qaAAYASJQmQBfAEpIAjoKTRTMeBBgWlR6iH44KEQkeycXNz0bXhsgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWkOTJE0fJQ5N0YANrhsOOdA7RImgLoaAviGNA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
The code should be fine as the type assertion changes the type from
string
to"expiredRequest" | "pendingRequest"
Actual Result
There was an error 5th line saying:
Additional Info
No response
The text was updated successfully, but these errors were encountered: