Skip to content
Justice Tech School

TypeScript Tutorial

JavaScript with a type system that catches mistakes early.

Start learning TypeScript
Getting started4 lessons
  1. 1TypeScript IntroductionJavaScript with types.
  2. 2TypeScript Get StartedInstall Node.js, then npm install -g typescript.
  3. 3tsconfig.jsontsconfig.json configures the compiler.
  4. 4TypeScript SyntaxTypeScript is a superset of JavaScript, so every JavaScript program is valid.
Basics9 lessons
  1. 5Variables: let and constPrefer const, use let when a value changes and avoid var.
  2. 6Type InferenceTypeScript works out types from values, so let n = 5 is a number.
  3. 7Numbers and Stringsnumber covers integers and floats.
  4. 8any, unknown and neverany switches off checking.
  5. 9null, undefined and Strict Null ChecksWith strictNullChecks, null and undefined are separate types.
  6. 10Type Assertionsas tells the compiler to treat a value as another type.
  7. 11TypeScript OperatorsArithmetic, comparison and logical operators work as in JavaScript.
  8. 12Objects and DestructuringObjects hold named properties.
  9. 13Typed Array Methodsmap, filter, reduce, find, some, every and flatMap keep their types, and generics let Type.
Types29 lessons
  1. 14Basic Typesstring, number, boolean and more.
  2. 15Arrays and TuplesTyped lists.
  3. 16Objects, Interfaces and Type AliasesDescribing shapes.
  4. 17Unions and Literal TypesOne of several types.
  5. 18EnumsNamed constants.
  6. 19Literal Types and const AssertionsA literal type allows only one exact value.
  7. 20Intersection TypesA & B combines types: a value must satisfy both.
  8. 21Type Aliases vs InterfacesBoth describe object shapes.
  9. 22Index Signatures and RecordsAn index signature describes objects with unknown keys: { [key: string]: number }.
  10. 23Readonly and Named Tuplesreadonly arrays and properties prevent changes.
  11. 24Basic TypesTypeScript adds types to JavaScript.
  12. 25Type InferenceTypeScript infers types from values, so you often do not need annotations.
  13. 26Arrays and TuplesArrays use number[] or Array<number>.
  14. 27any, unknown and neverany turns off checking.
  15. 28Union TypesA union allows several types with |.
  16. 29Literal TypesA literal type allows only exact values.
  17. 30Type Aliasestype gives a name to any type.
  18. 31InterfacesAn interface describes an object shape and can be extended and implemented by classes.
  19. 32Extending InterfacesInterfaces extend others to add properties without repeating them.
  20. 33readonly and Optional Propertiesreadonly stops reassignment after creation.
  21. 34EnumsEnums name a set of constants.
  22. 35Type Assertionsas tells the compiler to treat a value as a type.
  23. 36Type Narrowingtypeof, instanceof, in and equality checks narrow a union inside a branch.
  24. 37Discriminated UnionsGive each member a literal kind property.
  25. 38null and undefined ChecksWith strictNullChecks, null and undefined are separate types.
  26. 39void and nevervoid is for functions that return nothing.
  27. 40Index SignaturesAn index signature types an object with unknown keys.
  28. 41RecordRecord<K, V> builds an object type with keys K and values V.
  29. 42Practice: Typed Event EmitterUse a generic map of event names to payload types to make an emitter that cannot be misuse.
Control flow3 lessons
  1. 43Type Narrowing and GuardsTypeScript narrows types after checks: typeof, instanceof, in, equality and truthiness.
  2. 44Exhaustive ChecksAssigning the leftover value to never in a default case makes the compiler complain when a.
  3. 45Loops and Iterationfor, for of, for in, while and array methods all work.
Functions and generics17 lessons
  1. 46FunctionsTyping parameters and returns.
  2. 47GenericsReusable typed code.
  3. 48Utility TypesPartial, Pick, Omit, Record.
  4. 49Optional, Default and Rest ParametersMark optional parameters with ?, give defaults with =, and collect extra arguments with ...
  5. 50Function Types and OverloadsA function type is (a: number) => string.
  6. 51this, void and CallbacksFunctions can declare the type of this.
  7. 52Generic Constraints and DefaultsT extends X limits what T can be.
  8. 53Generic Classes and InterfacesClasses and interfaces can take type parameters, such as a typed Stack or a Result type.
  9. 54Function TypesType parameters and the return value.
  10. 55Optional and Default ParametersMark a parameter optional with ? or give a default value.
  11. 56Rest ParametersCollect extra arguments into a typed array.
  12. 57Function OverloadsOverloads declare several call signatures for one implementation.
  13. 58GenericsGenerics make code reusable for many types while keeping safety.
  14. 59Generic ConstraintsUse extends to require a shape from T.
  15. 60Generic Interfaces and TypesInterfaces and aliases can take type parameters too.
  16. 61keyofkeyof gives the union of an object type's keys.
  17. 62typeof in Typestypeof in a type position copies the type of a value.
Classes and modules14 lessons
  1. 63ClassesMembers, visibility and constructors.
  2. 64Async, Promises and ModulesTyping promises.
  3. 65Class Modifierspublic, private, protected, readonly and static control access.
  4. 66Inheritance and Abstract Classesextends inherits from a class, super calls the parent and override marks replacements.
  5. 67Implementing InterfacesA class can implement several interfaces and the compiler checks every member.
  6. 68ES Modules and ImportsUse export and import.
  7. 69Declaration Files and Globals.d.ts files describe the types of JavaScript libraries.
  8. 70ClassesClasses have typed properties and methods and a constructor.
  9. 71public, private and protectedprivate limits access to the class, protected to subclasses.
  10. 72implementsA class can promise to follow an interface with implements.
  11. 73Abstract ClassesAn abstract class cannot be instantiated and may declare methods subclasses must write.
  12. 74Static and Accessorsstatic belongs to the class.
  13. 75Modules: import and exportFiles with import or export are modules.
  14. 76Decorators OverviewDecorators attach behaviour to classes and methods.
Advanced typesPremium5 lessons
  1. 77Mapped TypesA mapped type builds a new type by transforming each key: { [K in keyof T]: .
  2. 78Conditional Types and inferT extends U ? X : Y chooses a type based on a condition.
  3. 79Template Literal TypesTemplate literal types build string types from other types, such as "on" + Capitalize<Even.
  4. 80More Utility TypesExclude, Extract, NonNullable, ReturnType, Parameters, Awaited, InstanceType and Required .
  5. 81Decorators and SymbolsDecorators annotate classes and members, and are used by Angular and NestJS.
Async and toolingPremium6 lessons
  1. 82Promises and async/await Typesasync functions return Promise<T>.
  2. 83Error Handling and Result TypesCaught errors are unknown under strict mode, so narrow them.
  3. 84JSON and Runtime ValidationTypes vanish at runtime, so data from the network needs validation.
  4. 85TypeScript with the DOMQuery results are nullable, so check them.
  5. 86Testing TypeScriptUse Vitest or Jest with TypeScript.
  6. 87Linting, Formatting and Build ToolsESLint with typescript-eslint finds bugs, Prettier formats, and bundlers such as Vite, esb.
TypeScript in practicePremium5 lessons
  1. 88Typed Express APIsAdd @types/express for typed requests and responses.
  2. 89TypeScript with ReactType component props with an interface, hooks with generics such as useState<number>, and .
  3. 90Project References and MonoreposProject references split large codebases into smaller TypeScript projects that build incre.
  4. 91Migrating JavaScript to TypeScriptRename files gradually from .js to .ts, enable allowJs and checkJs, start with strict off .
  5. 92TypeScript Best PracticesEnable strict, avoid any, prefer unknown, use unions and discriminated unions instead of e.
More types9 lessons
  1. 93Partial, Pick and OmitPartial makes all properties optional, Pick keeps some and Omit removes some.
  2. 94Readonly and RequiredReadonly freezes properties in the type.
  3. 95Mapped TypesA mapped type builds a new type by looping over keys.
  4. 96Conditional TypesT extends U ? X : Y picks a type by a condition.
  5. 97Template Literal TypesBuild string types from others with template syntax.
  6. 98as constas const makes values readonly literals, great for lookup tables and tuples.
  7. 99Custom Type GuardsA function returning x is T tells the compiler a check narrows the type.
  8. 100satisfiessatisfies checks a value against a type without widening it.
  9. 101Inferring with inferinfer captures a type inside a conditional type.
Tooling basics13 lessons
  1. 102Promises and async TypesAsync functions return Promise<T>.
  2. 103Typing ErrorsCaught errors are unknown.
  3. 104tsconfig.jsontsconfig.json sets compiler options.
  4. 105Useful Strict FlagsnoImplicitAny, strictNullChecks, noUncheckedIndexedAccess and exactOptionalPropertyTypes c.
  5. 106Using tscnpx tsc compiles, tsc --noEmit only checks and tsc --watch rebuilds on change.
  6. 107Using JavaScript LibrariesInstall @types/pkg for libraries without types.
  7. 108Generic ClassesClasses can take type parameters for containers.
  8. 109Immutable UpdatesUse readonly arrays and spread to update without mutating.
  9. 110Object Types and Excess PropertiesObject literals are checked for extra properties.
  10. 111Exhaustive ChecksUse never in the default branch so a new union member causes a compile error.
  11. 112Practice: Typed Todo ListModel data with an interface, then write small typed functions.
  12. 113Practice: Generic CacheCombine Map and generics for a typed cache.
  13. 114Practice: API Result TypeModel success and failure with a discriminated union.
Next steps2 lessons
  1. 115What Next?Where to go after the basics.
  2. 116Practice ProjectsBuild a typed todo API, a React app with TypeScript, a CLI tool and a small library publis.