

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
With dynamic property keys we've only used the string type so far, and most of the time, that's all you need. However, JavaScript also supports number and symbols as property keys. TypeScript actually has a built-in type called PropertyKey that represents all possible property key types:
// this is a built-in type
type PropertyKey = string | number | symbol;
A symbol is a unique and immutable data type that may be used as an object property name. It's kinda like a string, but it's guaranteed to be unique.
So, instead of:
type InfrastructureTags = {
[key: string]: any;
};
We can allow number and symbol keys (the JS default) like this:
type InfrastructureTags = {
[key: PropertyKey]: any;
};
const janesServer: InfrastructureTags = {
name: "Jane's Server",
1: 420,
[Symbol("role")]: "Admin",
};
To read or write a symbol-keyed property, use the symbol itself with bracket notation. Dot notation won't work.
const ROLE = Symbol("role");
const user = { [ROLE]: "Admin" };
user[ROLE]; // "Admin"
// user.ROLE; // undefined
New optional security features were added to Support.ai preferences. Management wants all mail users to enable at least one security method.
Complete the isSecure function. It takes a MailPreferences as input and returns a boolean.
true.false.