capypad
0 day streak
typescript / beginner
Snippet

Function Parameter Types

In TypeScript, you can specify types for both function parameters and the value the function returns.

snippet.ts
typescript
1
2
3
4
5
function greet(person: string): string {
return "Hello, " + person;
}
 
const message = greet("Anna");
Breakdown
1
person: string
The function expects one argument, which must be a string.
2
): string {
The colon after the parentheses indicates the function will return a string.
3
greet("Anna")
Calling the function with a valid string argument.