You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript is not respecting the callback of Number.isFinite.
Example
typeProduct={quantity?: number};constproduct: undefined|Product={quantity: 34,}// TypeScript error! product.quantity > 3 returns error because can be undefined (?? what)if(Number.isFinite(product?.quantity)&&product.quantity>3){}
Explanation
Number.isFinite always return false to every variable that is not number (or better, typeof equals number). You can try all the types (including objects) and will fail if the parameter to Number.isFinite is not a number.
Expected return
// No errors is right-hand conditional because the left conditional need be a number to continue👇!!if(Number.isFinite(product?.quantity)&&product.quantity>3){}// ✅
TypeScript is not respecting the callback of
Number.isFinite
.Example
Explanation
Number.isFinite
always return false to every variable that is notnumber
(or better,typeof
equalsnumber
). You can try all the types (including objects) and will fail if the parameter toNumber.isFinite
is not a number.Expected return
Solution (partial)
To resolve this for a while, can replace the
to
The text was updated successfully, but these errors were encountered: