TypeScript Tutorial · TypeScript Basics · Lesson 1 of 25
TypeScript Introduction
What TypeScript adds to JavaScript and why most large projects use it.
What is TypeScript?
TypeScript is JavaScript with types. You describe the shape of your data — "this is a number", "this object has a name string" — and the TypeScript compiler checks your code before it runs, catching typos, wrong arguments and missing properties.
TypeScript compiles to plain JavaScript, so it runs anywhere JavaScript runs: browsers, Node.js, Deno, Bun.
function greet(name: string): string {
return `Hello, ${name}!`;
}
console.log(greet("TypeScript"));
// @ts-expect-error — Argument of type 'number' is not assignable to parameter of type 'string'.
greet(42);
Output
Hello, TypeScript!
Why use it?
- Fewer bugs: many errors are caught while you type, not by your users.
- Better tooling: autocomplete, go-to-definition and safe renames in your editor.
- Self-documenting code: types explain what functions expect and return.
It's the default for React, Angular, Vue and Node.js projects — and a frequent interview topic.
Prerequisites
You should know JavaScript basics first — see the JavaScript tutorial.
Running examples on this site
Examples run in your browser: types are removed and the JavaScript runs, so you see the runtime output. Lines marked // @ts-expect-error show code the compiler would reject — in your editor you'd see the red squiggle.
Test yourself
What does the TypeScript compiler produce?
Machine codeJavaScriptJava bytecodeWebAssembly only
Show answer
Answer: JavaScript