Skip to main content
Module 3 · Lesson 1 of 25/22 in the course~15 min
Module lessons (1/2)

Typical functions

Lesson preview6 hands-on exercises readyCourse TypeScript · Module 3 — Generics and Functions

Note optional parameters, default values, rest params, reusable type signatures, and void.

What you'll learn in this lesson

  • Note mandatory, optional (lastName?: string) and default value (exponent: number = 2) parameters.
  • Extract and reuse function signatures via type alias ((a: number, b: number) => number).
  • Model safe callbacks with : void and recognize why void in callback returns also accepts return-ignored functions.
  • Use typed rest parameters (...values: number[]) and understand overloads with respect to unions.

Overview

Functions are the behavioral units of every TypeScript codebase. Typing its parameters and return means transforming the caller into an ally automatically controlled by the IDE.

A parameter marked with ? must follow all the mandatory parameters and takes type T | undefined. A parameter with a default value (rate: number = 0.22) automatically infers the type and does not require ?.

Sections covered in this lesson

  1. 1Optional parameters, default and rest
  2. 2Function Type Expressions and Callbacks : void
  3. 3Guided practice
  4. 4Check for understanding
Pro Lesson · Module 3 — Generics and Functions

Unlock "Typical functions" and the full Course TypeScript curriculum

Note optional parameters, default values, rest params, reusable type signatures, and void.

Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course TypeScript plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.