Closed as duplicate of#10257
Closed as duplicate of#10257
Description
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
Repro Code
const myNumber = 25
const max = 90
const percent = `${(Math.min(myNumber, max)) / 100}%` as `${number}%`;
ESLint Config
{
"rules": {
"@typescript-eslint/no-unnecessary-type-assertion": "error"
}
}
tsconfig
Expected Result
There should be no error in the provided playground
Actual Result
There’s an error in line 4:
This assertion is unnecessary since it does not change the type of the expression. 4:17 - 4:70
Additional Info
Without the type assertion, percent
would just be inferred as string
, but we want it to be ${number}%
.
While it’s true that as const
would give us the correct inference here, as ${number}%
should be allowed, too.