

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
The TS-specific void type represents the return value of functions that don't return a value.
function logMessage(message: string): void {
console.log(message);
// nothing is returned here!
}
In JavaScript, a function without a return statement returns undefined by default... but that's kinda vague. TypeScript uses the void keyword to indicate that truly nothing is returned.
In other words, void more explicitly communicates the intent that a function returns nothing.
Hover the logSystemEvent function to see that it returns void. The problem is, at Support.ai, we don't want to simply log our logs to the console, we want to do other things, like store them in a remote database.
Update the logSystemEvent function to return the log as a string instead of logging it to the console.