

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Function Type Syntax
incomplete
2: Inferred Return Types
incomplete
3: Void
incomplete
4: Function Types
incomplete
5: Type Alias
incomplete
6: Importing Types
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
One of the most useful places for explicit types is in function signatures. For example:
function createMessage(name: string, a: number, b: number): string {
return `${name} scored ${a + b}`;
}
The : type after each parameter specifies that parameter's type, and the : type after all the parameters specifies the return type. It works the same way with arrow functions:
const createMessage = (name: string, a: number, b: number): string => {
return `${name} scored ${a + b}`;
};
We need to calculate discounts for Support.ai customers. Run the function as-is, and notice that tsc is showing us some compile-time errors.
Fix the calculateTotal function by using the proper types. It should accept three parameters:
price: a number representing the base pricequantity: a number representing how many support chats they've purchaseddiscount: a number representing discount percentage (e.g., 0.1 for 10%)Then return the total price (a number) after applying the discount.