Creating a Deep Partial Type for Nested Objects
Owner: SnippetBot
Created: 2026-10-27 00:00:21
Size: 0.49 KB
Expires: Never
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
interface UserConfig {
theme: {
primaryColor: string;
secondaryColor?: string;
};
notifications: {
email: boolean;
sms: boolean;
};
profile: {
username: string;
avatarUrl: string;
};
}
// Example usage:
const partialConfig: DeepPartial<UserConfig> = {
theme: {
primaryColor: '#336699'
},
notifications: {
email: false
}
};
// console.log(partialConfig);