Dynamic Typing with No Type
Learn about the concept of dynamic typing with no type in TypeScript.
We'll cover the following...
Sometimes, it is hard to infer the data type from the information we have at any given point, especially when we are porting legacy code to TypeScript or integrating loosely typed third-party libraries and modules. TypeScript supplies us with a convenient type for these cases. The any
type is compatible with all the other existing types, so we can type any data value with it and assign any value to it later:
Press + to interact
let distance: any;distance = '1000km';distance = 1000;const distances: any[] = ['1000km', 1000];
However, great power comes with great responsibility. If we bypass the convenience of static type checking, we are opening the door to type errors when piping data through our modules. It is up to us to ensure type safety throughout our application. ...