← TypeScript for Beginners

Lesson 3 of 3 · 8 min

Typed functions

Annotate inputs and outputs: function add(a: number, b: number): number { return a + b }.

The compiler then warns whenever a caller passes the wrong kind of value.

Practice

Write a typed function that doubles a number and returns a number.

Quiz

+50 pts
1. Return types go…
2. Typed functions prevent…

Optional resources

Your lesson toolkit

No purchase or partner signup is required to complete this course or earn quiz points.

These are official product links, not active affiliate links. Learnly does not currently earn a commission from them.

TypeScript Playground

Experiment with types and see compiler feedback instantly.

Free browser tool.

Explore tool