typescript / beginner
Snippet
Basic Function Types
In TypeScript, you can define the types of the parameters a function receives and the type of the value it returns.
snippet.ts
1
2
3
function greet(name: string): string {return "Hello, " + name;}
Breakdown
1
name: string
Specifies that the 'name' parameter must be a string.
2
): string {
Specifies that the function must return a string value.