

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: Object Literal Types
incomplete
2: Extra Properties
incomplete
3: Optional Object Properties
incomplete
4: Empty Object Type
incomplete
5: Discriminated Unions
incomplete
6: Sets
incomplete
7: Maps
incomplete
8: Dynamic Keys
incomplete
9: Dynamic Default Properties
incomplete
10: PropertyKey
incomplete
11: Readonly Modifier
incomplete
12: 'As Const' and Object.freeze
incomplete
13: Satisfies
incomplete
14: Function Overloads
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Okay, I know I said unions were my favorite thing, and that's true when comparing TS to Go. But when it comes to the most useful "upgrade" from JavaScript to TypeScript, it's adding types to objects.
Object literal types allow you to describe the shape of an object:
function logSaiyan(saiyan: { name: string; power: number }) {
console.log(`${saiyan.name} has power level: ${saiyan.power}!`);
// ...
}
Or, more likely, you'll define the object type first:
type Saiyan = {
name: string;
power: number;
};
function logSaiyan(saiyan: Saiyan) {
console.log(`${saiyan.name} has power level: ${saiyan.power}!`);
// ...
}
It's so nice to get a little red squiggly line in your editor when you misspell a property name in TypeScript! JavaScript won't fail until you run it...
Support.ai is adding an internal email service for communication between workers and customers.