Skip to content
dreamcode
dreamcode
Map
Functions
Lesson 3 of 26
+15 XP on finish
TYPESCRIPTChapter 1 · TS Basics

Function parameter and return types

In TypeScript, you must annotate function parameters and their return types. This ensures callers pass the correct arguments and receive the expected outputs.

Worked example

How it reads

  • (meters: number) restricts parameter inputs to numbers only
  • : string asserts that the function must return a string
Cloud tip: Functions that do not return any value should be annotated with a return type of void.
index.ts
TYPESCRIPT
type-checked, then run in your browser
Console
Run your code to see its output here.
YOUR TURN

Write average(values: number[]): number and log average([2, 4, 9]): 5.

Press Run to check your work.