TypeScript is a free, open-source superset of JavaScript that adds a static type system. You write .ts files with type annotations, the compiler checks them for mistakes, and the types are then removed to produce plain JavaScript that runs in any browser or in Node.js. Web developers use it because it catches whole classes of bugs before the code runs and makes large codebases easier to navigate and refactor.
If you have written some JavaScript, TypeScript will feel familiar: every valid JavaScript program is also valid TypeScript syntax, and you add types gradually where they help most.
TypeScript is a language and a compiler developed by Microsoft and released as open source in 2012. It is a superset of JavaScript: it keeps all the JavaScript you already know and adds optional type annotations, interfaces, generics and a few extra constructs.
The key idea is that types exist only at development time. Browsers do not run TypeScript. A build step (the TypeScript compiler tsc, or a bundler such as Vite or esbuild) checks the types and emits ordinary JavaScript.
| Aspect | JavaScript | TypeScript |
|---|---|---|
| Typing | Dynamic, checked at run time | Static, checked before run time |
| File extension | .js, .mjs | .ts, .tsx |
| Runs in the browser | Directly | After compiling to JavaScript |
| Editor help | Basic inference | Precise autocomplete and refactoring |
| Learning curve | Lower | Slightly higher |
In JavaScript, a function can receive anything, and mistakes only appear when that line runs.
Nothing warns you that "free" is not a number. In a large application, such a value may travel through ten functions before it breaks something far from the real cause. TypeScript moves that failure to the moment you type the mistake.
Add a type annotation after each parameter and after the parameter list for the return type.
The compiler reports the second call as an error in your editor and when you run tsc. By default tsc still emits JavaScript even with errors, but most projects enable noEmitOnError or run the type check in CI so that broken code never ships.
To try it locally:
tsc --init creates a tsconfig.json file, which controls how strict the checks are and which JavaScript version is produced.
You do not have to annotate everything. TypeScript infers types from values, so annotate function parameters and public boundaries, and let inference handle local variables.
Describe the shape of objects once and reuse it.
A value can be one of several types, and the compiler narrows it as you check.
Generics let one function or type work with many types while keeping type safety.
null checks fail at compile time.TypeScript is not free. You add a build step, you write extra annotations, and complex generic types can be hard to read. Types are also erased at run time, so they do not validate data coming from an API or a form: a server can still return something that does not match your interface. For that, validate at the boundary with a schema library or manual checks.
For small scripts and quick prototypes, plain JavaScript may be faster. For applications that several people maintain for months or years, the safety usually repays the effort.
npm init -y.npm install --save-dev typescript.npx tsc --init and keep "strict": true enabled..js file to .ts and fix the errors the compiler reports.allowJs lets TypeScript and JavaScript files coexist.Recent Node.js versions can also run some TypeScript files directly by stripping types, but you still need tsc or an editor to type check them.
It is a superset: JavaScript plus a type system. The output is plain JavaScript, so everything you learn about JavaScript still applies.
No. Types are removed at compile time, so the runtime performance is the same as the equivalent JavaScript. The gain is in correctness and productivity.
Yes. TypeScript builds on JavaScript semantics, so understanding functions, objects, the DOM and asynchronous code first makes the types much easier to understand.
Yes. Both support it well, and the official project generators offer TypeScript templates, using .tsx files for React components.
TypeScript is JavaScript with static types, compiled to plain JavaScript before it runs. It catches errors early, improves editor tooling and makes large web applications easier to maintain. Start with strict mode, annotate function boundaries, let inference do the rest, and remember that types do not validate data at run time.