
TypeScript adds static type checking to JavaScript. It does not change the way JavaScript runs in the browser or in Node.js; instead, it checks code before it is executed and then produces regular JavaScript.
Function parameters and return values are a useful first place to add types:
function formatGreeting(name: string): string {
return `Hello, ${name}!`;
}
This makes the function's expectations visible to anyone using it. Editors can also catch incorrect calls before they become runtime bugs.
When an application passes the same shape of data between components or services, an interface documents that shape:
interface User {
id: number;
name: string;
isActive: boolean;
}
Types are particularly valuable at boundaries such as API responses, form values, and configuration objects. They help a team discover mismatches close to where they are introduced.
Avoid using any as a default escape hatch. If a value is genuinely unknown, use unknown and narrow it before working with it. Small, accurate types are more helpful than trying to describe every detail of an application at once.
The goal is not to make every line look complicated. The goal is to make important assumptions explicit so refactoring becomes more predictable.