# TypeScript
TypeScript adds static type checking to JavaScript. It helps describe data and function contracts, find mistakes before execution, and make refactoring safer. The runtime still executes JavaScript; types do not become automatic checks on every value.
# One function, two views
TypeScript source:
function greet(name: string): string {
return `Hello, ${name}`;
}
greet('Ada');
The relevant emitted JavaScript, with type annotations removed:
function greet(name) {
return `Hello, ${name}`;
}
greet('Ada');
TypeScript would reject greet(42) when checking this program. A JavaScript caller can still pass 42 at runtime: the annotation did not insert a validation function. This distinction matters especially for JSON, user input and DOM lookups.
# Which tool does what?
| Operation | Purpose | Typical tool |
|---|---|---|
| Type-checking | Check whether the source obeys its declared contracts | TypeScript compiler (tsc) |
| Transpilation | Produce JavaScript from TypeScript or newer syntax | tsc, or a configured loader/transpiler |
| Bundling | Follow imports and produce browser assets | Webpack |
| Runtime validation | Check actual input values | Code you execute, or a validation library |
Types are mostly erased; some TypeScript features also generate JavaScript. Browser code must be emitted in a form the target browsers support. A successful type check does not prove the business logic is correct—tests cover behavior.
# Learning path
- Types and contracts: inference, narrowing, interfaces, classes and generics.
- Compiler and DOM: configuration, modules, null checks and API boundaries.
- Webpack: connect the typed application to its HTML and bundle.
Try it: change the function call to greet(42), inspect the type error, then compare the emitted JavaScript with the TypeScript source. Do not suppress the error with any; decide which input the function should actually accept.