Functions

Learn about TypeScript function type safety, optional parameters, default parameters, and rest parameters,

Exploring the type system with functions

TypeScript language can be used to introduce further type safety whenever functions are used. Functions can use optional parameters and spread syntax. We will look at how we can define a function signature in such a manner that if a function defines another function as a parameter, we can make sure that the function we pass in has the correct parameters.

Optional parameters

Similar to tuples in TypeScript, we can specify that a function can have optional elements in the same way, using the question mark (?).

Consider the following code:

Get hands-on with 1200+ tech skills courses.