What Is TypeScript?
TypeScript is a statically checked superset of JavaScript. It adds a type system, interfaces, generics, and developer tooling while retaining JavaScript's runtime model. TypeScript source is normally compiled (or transpiled) into JavaScript, which is what browsers and Node.js execute.
The type system helps catch mistakes before a program runs: passing a string where a number is expected, accessing a property that may not exist, or forgetting to handle a variant in a union. It also improves editor autocomplete, navigation, and refactoring.
Types do not automatically validate external data at runtime. A value received from an API is still untrusted until your program checks it. TypeScript's guarantees are strongest when the codebase uses strict settings and avoids unnecessary any assertions.
Think of TypeScript as a development-time safety net, not a replacement runtime or a substitute for validating untrusted input.
function formatPrice(amount: number, currency: string): string {
return `${currency} ${amount.toFixed(2)}`;
}
formatPrice(12.5, "INR");
// formatPrice("12.5", "INR"); // Compile-time errortoFixed is a JavaScript runtime method.- TypeScript adds static analysis to JavaScript.
- Type annotations are removed during compilation.
- Types alone do not validate network or user input at runtime.
What executes in a standard browser after TypeScript compilation?