Sometimes, we want to fix Typescript error "This condition will always return ‘true’ since the types have no overlap".
In this article, we’ll look at how to fix Typescript error "This condition will always return ‘true’ since the types have no overlap".
How to fix Typescript error "This condition will always return ‘true’ since the types have no overlap"?
To fix Typescript error "This condition will always return ‘true’ since the types have no overlap", we should make sure our boolean isn’t always true.
For instance, we write
const frType: "Child" | "Infant" = "Child";
const rightType = frType !== "Child" || frType !== "Infant";
then we get the error because frType can either be 'Child' or 'Infant'.
But we’re checking if frType isn’t 'Child' or 'Infant', which means it always returns true since frType can only be 1 of the 2 values.
Conclusion
To fix Typescript error "This condition will always return ‘true’ since the types have no overlap", we should make sure our boolean isn’t always true.