import type {PartialOnUndefinedDeep} from 'type-fest';
interface Settings {
optionA: string;
optionB: number | undefined;
subOption: {
subOptionA: boolean;
subOptionB: boolean | undefined;
}
};
const testSettings: PartialOnUndefinedDeep<Settings> = {
optionA: 'foo',
// 👉 optionB is now optional and can be omitted
subOption: {
subOptionA: true,
// 👉 subOptionB is now optional as well and can be omitted
},
};
Create a deep version of another type where all keys accepting
undefinedtype are set to optional.This utility type is recursive, transforming at any level deep. By default, it does not affect arrays and tuples items unless you explicitly pass
{recurseIntoArrays: true}as the second type argument.Use-cases: