June 2021
Intermediate to advanced
398 pages
9h 35m
English
Functions also get to participate in the static-typing fun. The parameters and return values can have type annotations, and the function as a whole has its own static type.
TypeScript function parameters can have type annotations, with a similar syntax to what we’ve seen for variable declarations. The annotations work whether the function is a named function, an anonymous function, or a method of a class. All three of these examples have the same typing:
| | function priceOfTicket(row: number, accessType: string) : number { } |
| | |
| | let priceOfTicket = function(row: number, accessType: string) : number { } |
| | |
| | class Ticket { |
| | priceOfTicket(row: number, accessType: string) : number ... |