EasyEnv
TypeScript
Beginner

TypeScript

Learn TypeScript end to end. Types, interfaces, generics, classes, modules, utility and mapped types, declaration files, and the compiler.

18 lessons7.7h hands-on11 languages
Start learning freeTypeScript course

18 lessons, in order

  1. 1

    Hello, TypeScript

    Here is a small JavaScript program that is completely broken, and that JavaScript will happily run:

    What TypeScript isTsc compile stepRunning a .ts fileThe play button
    20 min
  2. 2

    Type Basics

    You can already run a .ts file. Now let's meet the basic building blocks: the primitive types TypeScript ships with, plus the two escape hatches (any...

    Primitive typesStringNumberBooleanNullUndefined+3
    25 min
  3. 3

    Arrays and Tuples

    A single value is rarely enough. You have a list of temperatures, a list of names, a list of prices. And the moment you have a list, a new kind of...

    Array typesReadonly arraysTuple typesFixed-length tuplesNamed tuple elements
    25 min
  4. 4

    Object Types and Interfaces

    Primitives and arrays carry you a long way, but most real data has a shape: a user has a name and an age, a request has a method and a path, a result...

    Object literal typesInterface keywordRequired vs optional propertiesStructural typingExcess property checks
    25 min
  5. 5

    Functions

    Functions are where most of the bugs live and where types pay off the most. A function's signature (its parameters and its return type) is a contract...

    Parameter typesReturn typesVoid returnDefault parametersRest parametersFunction type expressions+1
    25 min
  6. 6

    Union and Literal Types

    Some values are not one thing. A function that looks up a user either finds one or does not. A form field holds either a number the user typed or...

    Union typesString literal typesNumeric literal typesLiteral narrowing with as constUnion of object shapes
    25 min
  7. 7

    Type Narrowing

    A union says "this value is one of several types". Narrowing is the compiler's process of figuring out which one, based on the runtime checks you...

    Typeof narrowingTruthiness narrowingEquality narrowingIn operator narrowingInstanceof narrowingDiscriminated unions+1
    30 min
  8. 8

    Type Aliases vs Interfaces

    You have been writing object shapes inline, and it has been fine because the shapes were small. Now here is a function signature from a real codebase:

    Type aliasesInterface declarationsExtending interfacesIntersection typesDeclaration mergingWhen to pick which
    20 min
  9. 9

    Optional, Readonly, and Nullable

    The single most common runtime error in JavaScript reads like this:

    Optional propertiesReadonly propertiesNon-null assertion operatorOptional chainingNullish coalescingStrictNullChecks
    25 min
  10. 10

    Enums

    Some values come from a short, fixed list. An order is pending, shipped or delivered. A log line is debug, info, warn or error. A direction is up,...

    Numeric enumsString enumsConst enumsEnums vs string literal unionsReverse mapping caveats
    20 min
  11. 11

    Generics

    You need a function that takes an array and returns its first element. Easy:

    Generic functionsGeneric interfacesType parametersType inference for genericsBounded generics with extendsDefault type parameters
    30 min
  12. 12

    Classes

    Here is a bank account written as a plain object:

    Class declarationsConstructorsInstance propertiesAccess modifiers (public, private, protected)Readonly fieldsParameter properties+1
    25 min
  13. 13

    Inheritance and Abstract Classes

    You have written three classes for a payments system: CardPayment, BankTransfer and Voucher. All three have an amount, a currency and a createdAt....

    Extends keywordSuper callsMethod overrideAbstract classesAbstract methodsImplements with interface
    25 min
  14. 14

    Modules

    Every TypeScript file is its own module. The moment a file has an import or export, its top-level names stop being globals and become module-scoped....

    ES module syntaxNamed exportsDefault exportType-only importsRe-exportsModule resolution basics
    25 min
  15. 15

    Utility Types

    TypeScript ships with a small library of generic types that take a type as input and return a transformed type as output. They have unassuming names...

    Partial<T>Required<T>Readonly<T>Pick<T, K>Omit<T, K>Record<K, V>+2
    30 min
  16. 16

    Mapped and Conditional Types

    The utility types you just used (Partial, Pick, Record, ReturnType) are all built from two language features: mapped types for transforming the keys...

    Keyof operatorMapped types syntaxKey remapping with asConditional typesInfer keywordDistributive conditional types
    30 min
  17. 17

    Declaration Files and Libraries

    You install a library, import it, and your editor lights up with autocomplete, parameter hints and the exact shape of every return value. You install...

    .d.ts filesDefinitelyTyped (@types packages)Ambient declarationsDeclare moduleTypeRoots and types option
    25 min
  18. 18

    tsconfig and the Compiler

    tsconfig.json is the file the TypeScript compiler reads to figure out what to compile and how. There are over a hundred options, but a real project...

    Tsconfig.jsonStrict modeTarget and libModule and moduleResolutionOutDir and rootDirIncremental and watch+1
    30 min
TypeScript Course: Hands-on, in 11 Languages | Engineering Courses