Closed as not planned
Closed as not planned
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
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Link to the rule's documentation
https://typescript-eslint.io/rules/no-unnecessary-condition/
Description
Let's say:
function foo(): string | undefined {
// bla bla bla
}
const bar = foo();
if (typeof bar === 'string') { // It's ok
// bla bla bla
}
One day, I refactored the foo
function to return string only:
function foo(): string {
// bla bla bla
}
const bar = foo();
if (typeof bar === 'string') { // Smelly code. bar is always string. But no-unnecessary-condition does not report it
// bla bla bla
}
Fail
const str:string = 'foo';
if (typeof str === 'string') {
// bla bla bla
}
Pass
const str:string|undefined = 'foo';
if (typeof str === 'string') {
// bla bla bla
}
Additional Info
No response