Settings with exact propertiesDeepReadonly that recursively makes properties readonlyDeepReadonly to create a readonly version of SettingsSettings with exact propertiesDeepReadonly that recursively makes properties readonlyDeepReadonly to create a readonly version of SettingsSettingsSettings with these exact properties: theme as a string, version as a number, and options as an object with darkMode as boolean and languages as a string array.Use type Settings = { ... } and define nested properties exactly as described.
DeepReadonlyDeepReadonly that takes a generic type T and makes all properties readonly recursively. Use readonly [P in keyof T] and conditional types to check if T[P] is an object to apply DeepReadonly again.Use a mapped type with readonly and a conditional type to recurse on nested objects.
Settings using DeepReadonlyReadonlySettings by applying DeepReadonly to Settings. Then create a constant settings of type ReadonlySettings with the exact values: theme as "dark", version as 1, options.darkMode as true, and options.languages as ["en", "fr"].Use type ReadonlySettings = DeepReadonly<Settings> and create a constant settings with the exact values.
settings objectconsole.log statement to print the settings object.Use console.log(settings) to print the object.
What is the main purpose of a mapped type in TypeScript?
Which of the following is the correct syntax to define a simple mapped type that makes all properties of T optional?
type PartialType = ??: correctly to make properties optional. type PartialType<T> = { [P in keyof T]: T[P] } keeps properties required. type PartialType<T> = { [P: string]: T } uses string keys incorrectly. type PartialType<T> = { [P in keyof T]: Optional } uses a non-existent Optional type.Given the following code, what is the type of DeepReadonly<User>?
type DeepReadonly<T> = {
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P]
};
interface User {
name: string;
address: {
city: string;
zip: number;
};
}readonly to all properties, including nested objects.name and address become readonly, and inside address, city and zip are also readonly.Identify the error in this deep transformation mapped type:
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
}How would you write a mapped type DeepNonNullable<T> that recursively removes null and undefined from all properties of T, including nested objects?
Pass the test and this pattern moves unknown