TS2367

error TS2367: This condition will always return ‘false’ since the types ‘{ message: string; }[] | undefined’ and ‘number’ have no overlap.

Broken Code ❌

1
2
3
4
5
function myTest(errors: { message: string; }[]): void {
if (errors === 0) {
throw new Error();
}
}

Fixed Code ✔️

An array cannot be 0, so doing a check for equality with 0 makes no sense. What may be useful instead is checking the array length:

1
2
3
4
5
function myTest(errors: { message: string; }[]): void {
if (errors.length === 0) {
throw new Error();
}
}