Skip to main content
D
TypeScript
TypeScript Functions

TypeScript Functions

TypeScript strictly types function inputs and outputs.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

Functions are the core building blocks of JavaScript. TypeScript allows developers to lock down exactly what type of data goes into a function as arguments, and exactly what type of data the function is allowed to return.

Syntax

Syntax
1/* this types a function */
2function addNumbers(a: number, b: number): number {
3  return a + b;
4}

Key Points

  • Define argument types inside the parentheses `(a: number)`.
  • Define the return type after the parentheses `(): number`.
  • Use `void` if the function does not return anything.
  • TypeScript throws an error if you pass the wrong number of arguments.

Up Next

Continue your journey with the next topic.

Go to TS Classes