ciis0
ciis0

Reputation: 503

unreachable code not reported in typescript

Given the following typescript code:

function foo(arg: boolean): string {
    if(arg){
        return 'abc';
    } else {
        return arg ? 'cde' : 'def';
    }
}

the cde is unreachable, but neither IntelliJ, SonarLint nor TSLint prints a warning.

If I replace the arg with an explicit arg == true in both places, IntelliJ shows an TS2367 error for the arg == true in the (second) return.

function foo(arg: boolean): string {
    if(arg == true){
        return 'abc';
    } else {
        return arg == true ? 'cde' : 'def'; // "arg == true" marked with TS2367 error
    }
}

How can I convince either tool to also report an error without the explicit equals check?

Upvotes: 0

Views: 32

Answers (0)

Related Questions