-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [no-unnecessary-type-assertion] false positive on evolving type #10334
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 a case of strange behaviour from TS. here is a playground with some annotations to show how things are weird The important bit is that if you inspect the type of the identifier, To clarify -- it's specifically the identifier This might be a bug in TS, TBH. It certainly seems like very strange behaviour from TS. |
I agree with @bradzacher that this looks like a TS bug. I would add, from playing with different TS versions in the playground, it appears that this behavior was introduced with 5.1. Seems like the next step here would be to get input from TS team to see if an unintentional regression occurred that can be fixed upstream... The keywords for this are "evolving any" |
There's another weird bit of behaviour I just noticed - when |
@bradzacher do you mean |
Filed microsoft/TypeScript#60514 |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.6.3&fileType=.tsx&code=LAKAJgpgxgNghgJwgAgGYFcB2UAuBLAe0zQIIAoBKALmU3QFsAjCBZAH2S0lT0wjFCRYiFBmz4iyRoko06TFoOjwkaLLkLFpALzKY5DZgmrIAbgTxgA3KFBiNk%2BnF4BGSsgDeoZMhgQcyAAeNiA%2BgcgAvFIyFCFhkSTksd7RuoEAhMkgAL62IPYSxE68AEzuXqG%2B-kFxQQnSCJS14VGopE0pOmSBWbkgQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWkOTJE0fJQ5N0UOdA7RI4MAF8QOoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDArugDTg10NM8AOXapUAYQAW6aAGsylDul4BfECqA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
The linter should not treat
baz(x!)
as an unnecessary type assertionActual Result
@typescript-eslint/no-unnecessary-type-assertion
rule warns about the assertion baz(x!) as unnecessary, suggesting it could be removed. Removing the assertion causes TypeScript to raise an error.Additional Info
No response
The text was updated successfully, but these errors were encountered: