Function type is a type that describes a function as a value.

A function type usually describes the types of the function’s parameters and its return value.

For example, in Typescript:

type Predicate = (value: string) => boolean

This defines a function type named Predicate for functions that take a string and return a boolean.

Function types are useful for:

  • Callbacks
  • Higher-order functions
  • Event handlers
  • Dependency injection

When a language supports function types, functions can often be passed around like other values.

Anki

id: function-type-definition deck: Computer Science::Data Types tags: data-types function-type

Q: What is a function type? A: A function type describes a function as a value, usually including its parameter types and return type.

id: function-type-use-cases deck: Computer Science::Data Types tags: data-types function-type callbacks

Q: What are function types useful for? A: Function types are useful for callbacks, higher-order functions, event handlers, and dependency injection.