TypeScript
A language that adds type checking to JavaScript. It can catch mistakes before your code runs, such as passing a string to a function that expects a number.
Also known as: TS
What TypeScript adds to JavaScript
TypeScript, often shortened to TS, lets you describe the values your code expects. For example, a component might require a product with a numeric price, while a callback might accept a product ID and return nothing. TypeScript checks whether callers follow those contracts. That is useful when changing shared code: if you rename a required property, the checker can flag typed code that still uses the old name.
From source code to the browser
You don't have to annotate every variable. Given let total = 0, TypeScript infers number from the initializer. Explicit annotations are useful at module boundaries, where you want the accepted inputs and outputs to be clear. TypeScript usually compares objects by shape: a variable with the required properties can satisfy an object type even if it has extra fields. Fresh object literals get an extra check for unexpected properties, which helps catch misspellings.
In a typical frontend build, the browser receives JavaScript. Type annotations and interfaces are removed; they don't become runtime checks. Projects configure the checker in tsconfig.json, commonly with strict enabled. Some build tools strip types without checking them, so teams often run tsc --noEmit separately in CI to report type errors without generating files.
Example: model a request result
type Result =
| { ok: true; name: string }
| { ok: false; message: string };
function describe(result: Result): string {
if (result.ok === true) {
return `Hello, ${result.name}`;
}
return result.message;
}
This is a discriminated union: the value of ok tells TypeScript which shape it is dealing with. Inside the first branch, name is available; in the other branch, message is available. The process of using a check to refine a type is called narrowing. Modeling the result this way avoids giving both branches optional fields that callers would have to check individually.
Where it helps and where it stops
Frontend teams use TypeScript for component props, application state, shared utilities, and API contracts. The checker can tell you when a caller misuses a typed API client, but it cannot tell you whether the server actually sent the promised data. An assertion like payload as User changes the type the checker uses; it neither converts nor validates the value. For an external payload, start with unknown and validate its shape at runtime. You still need tests for behavior that types can't express, such as whether a price calculation applies the right discount.
What interviewers look for
A common exercise is to fix a component that reads data before it has loaded. Model loading, success, and failure as separate cases, then narrow before reading fields specific to one case. Be ready to explain why checking a value is different from silencing the checker with as or !.