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
Item 19: Use Different Variables for Different Types
Things to Remember
While a variable's value can change, its type generally does not.
To avoid confusion, both for human readers and for the type checker, avoid reusing variables for differently typed values.
Code Samples
letproductId="12-34-56";fetchProduct(productId);productId=123456;// ~~~~~~ Type 'number' is not assignable to type 'string'fetchProductBySerialNumber(productId);// ~~~~~~~~~// Argument of type 'string' is not assignable to parameter of type 'number'