TypeScript encourages developers to think about data types explicitly, enhancing code clarity and catching potential errors early in the development process.
TypeScript consists of three main components:
When compiling a TypeScript file, two files are generated:
This separation allows for type checking without affecting the runtime JavaScript code.
any type in TypeScript is similar to types in JavaScript, allowing assignment of any data type.Type assertion allows you to tell the compiler to treat a value as a specific type:
let temp = 79 as any;
This forces TypeScript to view 79 as type any, leading to type inference of the temp variable as any.