8 Using functions

This chapter covers

  • Defining functions with static data types for the parameters and results
  • Working with optional function parameters
  • Defining function parameters with default values
  • Using rest parameters to capture multiple argument values
  • Overloading function types
  • Using assert functions as type guards

In this chapter, I explain how TypeScript is applied to functions, showing you how TypeScript helps prevent common problems when defining functions, dealing with parameters, and producing results. Table 8.1 summarizes the chapter.

Table 8.1 Chapter summary

Problem

Solution

Listing

Allow a function to be called with fewer arguments than parameters

Define optional parameters or define parameters with default ...

Get Essential TypeScript 5, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.