Lesson 13 of 55
15 mins readPython Function Signatures and Return Types
In Plain English
TypeScript enables complete type safety for function inputs and outputs. Learn how to annotate parameters, enforce explicit return types, and handle higher-order function callbacks.
Core Rules to Remember

Parameter Annotations: Enforces type matching on all arguments passed to functions.

Explicit Return Types: Guarantees functions return the expected contract, preventing accidental returns.
Live Interactive Example
Hit Run Code to see it liveAnnotating Functions and Callbacks
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Output Console
Click "Run Code" to view the rendered output.
How it works: calculateDiscount and formatCurrency have strict type contracts, preventing invalid arguments.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Type a Metric Transformer
Define a function type TransformFn that takes a number and returns a number.
Write a function processValues(values: number[], fn: TransformFn): number[] that maps over values using fn.
Call processValues([1, 2, 3], (x) => x * 10) and print the JSON stringified result.
1
2
3
4
5
6
7
8
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.