TypeScript introduction
What TypeScript adds to JavaScript, why teams use it and how code is compiled.
TypeScript is JavaScript with types. You describe what kind of value each variable, parameter and object should hold, and the compiler warns you about mistakes before the code runs — wrong property names, missing arguments, calling a method on something that might be undefined.
The compiler (tsc) removes the types and outputs plain JavaScript, so TypeScript runs anywhere JavaScript runs: browsers, Node.js, React, Angular.
Why companies ask for it
- Bugs are caught while typing instead of in production.
- Editors give accurate autocomplete and safe renaming.
- Types document the code, which helps large teams.
Angular is written in TypeScript, and most new React and Node projects use it too.
Example code
Try it in the TypeScript Playground or with tsc// greet.ts
function greet(name: string, years: number): string {
return "Hi " + name + ", " + years + " years of experience";
}
greet("Anu", 3); // OK
greet("Anu"); // error
greet(3, "Anu"); // error
Compiler / program output
greet.ts:6:1 - error TS2554: Expected 2 arguments, but got 1.
greet.ts:7:7 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
Found 2 errors.
Paste the code into the official TypeScript Playground in your browser, or install TypeScript (npm install -D typescript) and run npx tsc --noEmit to type-check. Names are fictional.
Key points
- TypeScript = JavaScript + types.
- Errors are caught at compile time, before running.
- tsc outputs plain JavaScript.
- Used widely with React, Angular and Node.js.
Quick check
What does the TypeScript compiler produce?
tsc checks types and then strips them, outputting JavaScript that browsers and Node can run.
Practice task
Open the TypeScript Playground, write a function that takes a price (number) and a GST rate (number) and returns the total, then try calling it with a string to see the error.
Interview corner
What are the benefits of TypeScript over JavaScript?
Static type checking catches many bugs before runtime, editors give better autocomplete and refactoring, and types act as documentation. It compiles to plain JavaScript, so there's no runtime cost.
Do TypeScript types exist at runtime?
No. Types are erased during compilation. To check data that arrives at runtime (API responses, form input) you still need runtime validation, for example with a library such as Zod.
Further reading
Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.
Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.