-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed as not planned
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginlocked 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 Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
My proposal is suitable for this project
- My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
- My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Description
I think there would be value in having a rule to avoid extra type-predicate checks when they're not necessary. This can help clean up type-predicates around a repo as types are changed, and also avoid unnecessary CPU cycles at runtime.
This rule would work similarly to no-unnecessary-type-assertion
.
Fail Cases
const test: "foo" = "foo";
const isFoo = (text: string): text is "foo" => {
return text === "foo";
}
// Should error here: at compile time we know the else branch will never get hit
if (isFoo(test)) {
console.log("FOO!");
} else {
console.log("BAR!");
}
Pass Cases
const test: string = "bar";
const isFoo = (text: string): text is "foo" => {
return text === "foo";
}
// Shouldn't error here: at compile time we cannot know if the else branch will be hit, and so the predicate usage makes sense.
if (isFoo(test)) {
console.log("FOO!");
} else {
console.log("BAR!");
}
Additional Info
No response
Metadata
Metadata
Assignees
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginlocked 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