typescript
/

TypeScript Function Types

Last Sync: Today

On this page

10
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

typescript

TypeScript Function Types

What are Function Types?

Function types define the structure of a function, including its parameters and return type.

Basic Function Type

TypeScriptRead-only
1
let add: (a: number, b: number) => number;

add = (x, y) => x + y;

Using Type Alias

TypeScriptRead-only
1
type AddFn = (a: number, b: number) => number;

const sum: AddFn = (a, b) => a + b;

Using Interface

TypeScriptRead-only
1
interface MultiplyFn {
  (a: number, b: number): number;
}

const multiply: MultiplyFn = (a, b) => a * b;

Callback Function Types

TypeScriptRead-only
1
function process(fn: (value: number) => number) {
  return fn(10);
}

Optional Parameters

TypeScriptRead-only
1
type Greet = (name?: string) => string;

Void Function Type

TypeScriptRead-only
1
type LogFn = (msg: string) => void;

Best Practices

  • Use type aliases for reusable function types
  • Use interfaces for complex definitions
  • Define clear parameter and return types
  • Avoid using any in function types

Common Mistakes

  • Not defining return types
  • Incorrect parameter order
  • Overusing any type
  • Ignoring function signature consistency

Conclusion

Function types in TypeScript ensure consistency and safety when working with functions, especially in large applications.

Try it yourself

type Add = (a: number, b: number) => number;
const add: Add = (a, b) => a + b;

Test Your Knowledge

Q1
of 3

Function type defines?

A
HTML
B
Structure
C
Style
D
API
Q2
of 3

Alias keyword?

A
interface
B
type
C
class
D
function
Q3
of 3

Return type arrow?

A
=>
B
->
C
::
D
:

Frequently Asked Questions

What is a function type?

It defines parameters and return type of a function.

Type vs Interface?

Both can define function types.

Why use function types?

To ensure consistency and type safety.

Previous

ts functions

Next

ts optional default

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.