TypeScript Essentials

Lesson 01 · 8 min

What changes if you know JS

TypeScript is JavaScript plus a contract. At runtime there are no types.

8 minLesson 1 of 10Practice includedAsk AI on any point

You already write JS. TypeScript isn't new semantics or a different runtime. It's a layer of checking before you run: the compiler reads annotations, complains about mismatches and throws the types away. The browser gets ordinary JavaScript. The same is said briefly in TypeScript in 5 minutes — worth keeping open alongside.

That's why typeof user in the console will never answer User: at runtime it's an ordinary object. The typeof operator in JavaScript looks at the value, not at the annotation. If you need to validate data, write the check yourself or use zod. TS doesn't do that.

JavaScript
TypeScript

A typo in JS is a surprise in production. In TS it's a red squiggly line.

AI

You can ask about this rule«Types are erased»

AI

You can ask about this point«Lesson summary»

Then why write types

  • Autocomplete knows the object's shape instead of guessing.
  • Refactoring: rename a field and the compiler shows every place.
  • A contract between functions, and between you and the API.
  • Documentation that doesn't lie, because it's checked.
One file is already TypeScript

The extension is .ts / .tsx. You build with tsc, Vite, Next — doesn't matter. What matters: turn on strict mode (strict: true) right away. It enables several flags at once: noImplicitAny, strictNullChecks and others — the list is in tsconfig: strict. Without it the compiler lets null through where you expect a string, and the point of TS disappears.

AI

You can ask about this point«Then why write types»

Check

Lock it in before you move on

  1. 1. What remains in JS after compiling const n: number = 1?

  2. 2. Can you check at runtime that a value has the type User?

PracticeSolve the lesson tasksA few short tasks in the editor. Check your code right away and see where it goes wrong.Start practice