@snailicide/build-config / utilities / PartialDeep
PartialDeep<T, Options>
ts
type PartialDeep<T, Options> = _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;Defined in: node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/partial-deep.d.ts:96
Create a type from another type with all keys and nested keys set to optional.
Use-cases:
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | - |
Options extends PartialDeepOptions | { } |
Example
import type {PartialDeep} from 'type-fest';
const settings: Settings = {
textEditor: {
fontSize: 14,
fontColor: '#000000',
fontWeight: 400
},
autocomplete: false,
autosave: true
};
const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
return {...settings, ...savedSettings};
}
settings = applySavedSettings({textEditor: {fontWeight: 500}});By default, this does not affect elements in array and tuple types. You can change this by passing {recurseIntoArrays: true} as the second type argument:
import type {PartialDeep} from 'type-fest';
type Settings = {
languages: string[];
}
const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
languages: [undefined]
};See
PartialDeepOptions