TypeScript is JavaScript plus a type system: you describe what shape your data has, and a checker tells you before the code runs where you have used it wrongly. Every TypeScript program becomes plain JavaScript before it executes, so learning TypeScript is learning JavaScript, with an extra layer. For a beginner the answer is: learn JavaScript’s fundamentals first, for a few weeks, then add TypeScript and never go back.
The difference in one example#
// JavaScript: runs, then fails at runtime, or worse, does the wrong thing
function total(items) {
return items.reduce((sum, item) => sum + item.price, 0);
}
total([{ price: 5 }, { cost: 3 }]); // NaN - a typo in the data, found by a user
// TypeScript: the same function, with the shape stated
type Item = { price: number };
function total(items: Item[]): number {
return items.reduce((sum, item) => sum + item.price, 0);
}
total([{ price: 5 }, { cost: 3 }]);
// Error: Object literal may only specify known properties, and 'cost' does not exist in type 'Item'.
The error appears in the editor as you type, before anything runs. That is the whole proposition: a class of bugs moves from “found in production” to “found while typing”.
What it catches#
- Calling a function with the wrong number or type of arguments.
- Reading a property that does not exist, including typos.
- Using a value that might be
nullorundefinedwithout checking. - Returning the wrong type, or forgetting to return.
- Mismatched import and export shapes.
Beyond errors, the types power the editor: autocomplete that knows every property, rename that finds every use, and documentation on hover. Many developers value that more than the error checking.
What it cannot catch#
Anything about values at runtime that the types did not describe. Data from an API is whatever the server sent, regardless of the type you declared for it. Logic errors — the right types, the wrong calculation — are untouched. And types are erased before the code runs, so there is no runtime enforcement at all; a type is a promise you make to the checker, not a guard.
The costs#
- A build step. TypeScript has to be compiled to JavaScript. Modern tools make this near-invisible, and Node can now run TypeScript files directly by stripping the types, but it is a step JavaScript did not have.
- Type syntax to learn. Basic annotations take an afternoon. Generics, utility types and the advanced corners take much longer, and a beginner can get lost there if they go too early.
- Friction with untyped code. A library without type definitions, or data of unknown shape, needs extra work to satisfy the checker.
- Time spent satisfying the checker rather than solving the problem, particularly early on, before the habits form.
Who uses which#
Surveys of professional developers put TypeScript usage at around 44% and rising, with JavaScript itself the most used language overall — because TypeScript developers are also JavaScript developers. Nearly every large front-end codebase, most Node back ends of any size, and the major frameworks’ own code are TypeScript. Plain JavaScript remains normal for small scripts, quick prototypes, and browser code where a build step is unwanted.
| Situation | Choose |
|---|---|
| Your first month of programming | JavaScript |
| Anything with more than a few files | TypeScript |
| A team project | TypeScript |
| A quick script or a single HTML page | JavaScript |
| Applying for front-end or Node jobs | TypeScript, non-negotiable |
A learning order that works#
- JavaScript fundamentals, plain. Variables, functions, arrays, objects, the DOM, promises. A few weeks. No types yet; there is enough to absorb.
- Add TypeScript with basic annotations. Parameter and return types, object types, arrays. Turn on
strictfrom the start so the habits are right. - Let the errors teach you. Each red squiggle is a small lesson about a mistake you were about to make. Read them.
- Generics and the rest later, when a real problem needs them. Do not study the advanced type system in the abstract.
Starting with TypeScript from day one is possible and some people prefer it. The risk is fighting the checker before understanding what it is checking, and concluding that programming is harder than it is.
Trying it in one minute#
npm install -g typescript
echo 'const n: number = "five";' > test.ts
tsc test.ts
# error TS2322: Type 'string' is not assignable to type 'number'.
Or open the TypeScript playground in a browser and paste any JavaScript; the errors appear on the right.
Questions people ask#
Is TypeScript a different language?
It is a superset: all JavaScript is valid TypeScript. The additions are types and a few conveniences, all erased at compile time.
Does TypeScript make code faster?
No. The output is ordinary JavaScript. The gain is fewer bugs and a better editor, not speed.
Can I use TypeScript in the browser directly?
Browsers run JavaScript, so it must be compiled first. Every bundler does this; for a single page without tools, use JavaScript.
Do I still need to learn JavaScript if I learn TypeScript?
You will learn it whether you mean to or not, because TypeScript is JavaScript underneath. Understanding what the compiled output does is part of being good at TypeScript.
Where to go next#
- JavaScript for beginners — step one.
- “error is of type unknown” — the first TypeScript error most people meet.
- TypeScript 7 — the current compiler.