Types from the start

What TypeScript adds to JavaScript, the basic types, and typed functions with optional, default and rest parameters.

About 4 hours of study

Learning objectives

Lessons

  1. 1

    Why TypeScript Intermediate

    What TypeScript adds to JavaScript, how the type checker finds mistakes before a program runs, type annotations and inference, and how a TypeScript program becomes JavaScript.

  2. 2

    Basic types: primitives, arrays, tuples and unknown Intermediate

    The primitive types, arrays and tuples, null and undefined under strict mode, literal types, and the difference between any and unknown.

  3. 3

    Typed functions Intermediate

    Parameter and return types, optional, default and rest parameters, function types for callbacks, void and never, and how TypeScript checks every call.

Module practice

Module quiz

1. When does TypeScript report a type error?
2. Which type is a tuple of a name and an age?
3. Inside function f(x?: string), what is the type of x?
4. Why prefer unknown to any for parsed JSON?
5. What is the type of a function that always throws?
6. Why does prompt() have the type string | null?

Shaping data ›