PokéRogue
    Preparing search index...
    UndefinedOnPartialDeep: T extends BuiltIns
    | Function
        ? T
        : T extends readonly unknown[]
            ? UndefinedOnPartialList<T>
            : T extends Map<infer K, infer V>
                ? Map<K, UndefinedOnPartialDeep<V>>
                : T extends ReadonlyMap<infer K, infer V>
                    ? ReadonlyMap<K, UndefinedOnPartialDeep<V>>
                    : T extends Set<infer K>
                        ? Set<UndefinedOnPartialDeep<K>>
                        : T extends ReadonlySet<infer K>
                            ? ReadonlySet<UndefinedOnPartialDeep<K>>
                            : T extends Record<any, any>
                                ? {
                                    [KeyType in keyof T]: undefined extends T[KeyType]
                                        ? UndefinedOnPartialDeep<(...)>
                                        | undefined
                                        : UndefinedOnPartialDeep<(...)[(...)]>
                                }
                                : T

    Create a deep version of another type where all optional keys are set to also accept undefined.

    Note: This is only needed when the exactOptionalPropertyTypes TSConfig setting is enabled.

    Use-cases:

    • When exactOptionalPropertyTypes is enabled, an object like {a: undefined} is not assignable to the type {a?: number}. You can use UndefinedOnPartialDeep<{a?: number}> to make it assignable.

    Type Parameters

    • T
    import type {UndefinedOnPartialDeep} from 'type-fest';

    type Settings = {
    optionA: string;
    optionB?: number;
    subOption: {
    subOptionA: boolean;
    subOptionB?: boolean;
    };
    };

    const testSettingsA: Settings = {
    optionA: 'foo',
    optionB: undefined, // TypeScript error if `exactOptionalPropertyTypes` is true.
    // @ts-expect-error
    subOption: {
    subOptionA: true,
    subOptionB: undefined, // TypeScript error if `exactOptionalPropertyTypes` is true
    },
    };

    const testSettingsB: UndefinedOnPartialDeep<Settings> = {
    optionA: 'foo',
    optionB: undefined, // `optionB` can be set to `undefined` now.
    subOption: {
    subOptionA: true,
    subOptionB: undefined, // `subOptionB` can be set to `undefined` now.
    },
    };