TypeScript - Functions

The major part of typing will happen for the functions and their arguments. Usually, TypeScript will be able to detect the expected type of variables based on their initialization. However, functions will always require input type definitions.

The argument of a function can also be a function, so you will need to understand how function type overlaps work.

Function type

I know how to create a function type, and I remember to specify the types of arguments (if present) and the return value type

Return value

I know how to specify the return type, and I use void keyword to indicate functions that are not expected to return anything

Spread arguments

I know how to type a function that can accept any number of arguments of a specific type using the (...rest: T[]) => ReturnValue spread syntax

Async functions

I know that I can mark a function as asynchronous by using the Promise<> wrapper on the returned value

Function as argument

I know how to properly type an argument that is expected to be a function. I also know that I can pass a function with different type as an argument as long as the types are overlapping

Icon of TypeScript
Icon of Functions
TypeScript skill
core
Functions
Ready to learn
Required technologies

I know how to create a function type, and I remember to specify the types of arguments (if present) and the return value type

I know how to specify the return type, and I use void keyword to indicate functions that are not expected to return anything

I know how to type a function that can accept any number of arguments of a specific type using the (...rest: T[]) => ReturnValue spread syntax

I know that I can mark a function as asynchronous by using the Promise<> wrapper on the returned value

I know how to properly type an argument that is expected to be a function. I also know that I can pass a function with different type as an argument as long as the types are overlapping

Close
Loading content