vendredi 13 novembre 2020

Is it possible to be warned when comparing a non-null value to null in Typescript?

Assuming --strictNullChecks is on.

When I create a variable and I implicitly say that it can't be null (e.g. a number) and then I compare the value of this variable to null, there is no warning saying "This condition will always return false" being emitted.

const a: number = 5;

// I would expect this to emit a warning, because the condition will always evaluate as false
if(a === null) { 
    // do something
}

// same here, this will always evaluate as true
if(a !== null) {
    // do something else
}

Is there a way to achieve this behavior?

Aucun commentaire:

Enregistrer un commentaire