Parameter and Return Type Annotations
Add types to function inputs and outputs.
Welcome
Typing function parameters and return values is one of the most important things you can do in TypeScript. It documents the contract and prevents bugs at call sites.
Parameter Types
Add a colon and type after each parameter name to annotate it.
function greet(name: string): string {
return 'Hello, ' + name;
}All lessons in this course
- Parameter and Return Type Annotations
- Optional and Default Parameters
- Rest Parameters and Spread with Types
- void, never, and Function Signatures