TypeScript
JavaScript with types that catch bugs before they run
Types and interfaces, unions and narrowing, classes, generics and utility types — run every example and watch the compiler catch mistakes instantly.
- 30 lessons
- 8 chapters
- Arabic & English
Your progress
What's inside
Lessons go from the basics to advanced topics. Read them in order, or jump to what you need.
Chapter 1
Getting Started
- 1TypeScript IntroductionTypeScript is JavaScript with types. It catches mistakes while you write code, before they ever reach your users, and then compiles to plain JavaScript that runs everywhere.
- 2TypeScript SetupInstall TypeScript with npm, compile files with the tsc command, and set up a real project with a tsconfig.json file created by npx tsc --init.
- 3Your First TypeScript ProgramWrite your first program: add type annotations to variables and functions, let TypeScript infer types for you, and read your first compiler error.
Chapter 2
Basic Types
- 4Primitive Types: string, number, booleanMeet the three types you'll use every day, string, number and boolean, and see how TypeScript stops you from mixing them up.
- 5Special Types: any, unknown, void, neverMeet the special types: any, which turns checking off, unknown, its safe alternative, void for functions that return nothing, never for things that never happen, and null and undefined in strict mode.
- 6Arrays and TuplesType arrays with number[] or Array<string>, make them read-only with readonly, and use tuples for fixed-length arrays where every position has its own type.
- 7Object TypesDescribe the shape of objects with object types, make properties optional with ? or read-only with readonly, and see how TypeScript catches typos and missing properties.
- 8Type InferenceLearn how TypeScript works out types on its own from initial values, return statements and context, and when you should still write types yourself.
Chapter 3
Functions
- 9TypeScript FunctionsType function parameters and return values, and use optional, default and rest parameters safely.
- 10Function Types and CallbacksDescribe functions themselves as types, type the callbacks you pass to other functions, and understand what void means for callbacks.
- 11Function OverloadsUse overload signatures when a function can be called in several ways and its result type depends on its input, and learn when a union type is simpler.
Chapter 4
Building Types
- 12Type Aliases and InterfacesName your types with type and interface, extend them to build bigger types, and learn when to choose each one.
- 13Union and Intersection TypesCombine types: a union A | B means "one or the other", and an intersection A & B means "both at once".
- 14Literal TypesRestrict a value to exact strings or numbers like "small" | "medium" | "large", use as const, and build string types with template literal types.
- 15EnumsGroup related named constants with numeric and string enums, see what they compile to, and compare them with unions of literal types.
- 16Type NarrowingTurn a wide type into a specific one with checks TypeScript understands: typeof, truthiness, equality, in, instanceof, discriminated unions and custom type guards.
- 17Type AssertionsTell the compiler you know a value's type with as, use the non-null assertion ! carefully, and prefer satisfies when you want checking without losing precise types.
Chapter 5
Classes
- 18TypeScript ClassesWrite classes with typed properties, constructors and methods, protect your data with public, private, protected and readonly, and shorten your code with parameter properties.
- 19Inheritance and Abstract ClassesExtend classes with extends and super, override methods safely with override, and use abstract classes as templates that subclasses must complete.
- 20Implementing InterfacesUse implements to promise that a class follows an interface, implement several interfaces in one class, and write code that depends on interfaces instead of concrete classes.
Chapter 6
Generics
Chapter 7
Advanced Types
- 23keyof, typeof and Indexed AccessDerive new types from existing types and values: keyof gives you the keys, typeof copies a value's type, and indexed access T["key"] picks out a property's type.
- 24Utility TypesTransform existing types with built-in helpers like Partial, Required, Readonly, Pick, Omit, Record and ReturnType, and see how they're built with mapped types.
Chapter 8
TypeScript in Practice
- 25TypeScript ModulesSplit code into files with import and export, share types with import type, and understand how TypeScript compiles modules and where library types come from.
- 26Async TypeScriptType asynchronous code: Promise<T>, async/await, error handling with unknown, Promise.all with tuples, and typing data that comes from a server.
- 27Strict Mode and tsconfig OptionsUnderstand exactly what "strict": true turns on, such as strictNullChecks and noImplicitAny, plus extra safety options worth enabling in your projects.
- 28TypeScript with the DOMType your web page code: element types like HTMLInputElement, handling the null that querySelector returns, typed events, and safe form handling.
- 29TypeScript in Real ProjectsSee how TypeScript is used with Node.js and Express, React and NestJS, how to start each kind of project, and how types flow between the backend and the frontend.
- 30TypeScript Best PracticesHabits that keep TypeScript code safe and readable: strict mode, avoiding any, letting inference work, modeling data with unions, and validating data at your program's boundaries.