-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed as duplicate of#10257
Closed as duplicate of#10257
Copy link
Labels
bugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a look
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.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a look