ts-type-forge
    Preparing search index...

    Type Alias PartiallyNullable<T, K>

    PartiallyNullable: MergeIntersection<
        Omit<T, K> & { [P in K]: T[P] | undefined },
    >

    Creates a type where specified keys K of T are made nullable (i.e., | undefined is added to their type). The resulting type is a merged intersection for better readability.

    Type Parameters

    • T

      The original type.

    • K extends keyof T

      The keys to make nullable.

    A new type with keys K made nullable.

    type Data = { a: number; b: string; c: boolean };
    type PartiallyNullableData = PartiallyNullable<Data, 'a' | 'b'>;
    // Result: { a: number | undefined; b: string | undefined; c: boolean }