Function isPropertyNotUndefined

  • Returns a type guard function, which receives an object and checks if the given property is not undefined. Narrows the type of the given property within the object type from T | undefined to just T.

    Example:

    incoming type is { a: number, b: string | undefined }

    outgoing type of returned type guard from propertyNotUndefined('b') is { a: number, b: string }

    Type Parameters

    • T

    • P extends string | number | symbol

    Parameters

    • property: P

      name of the property to check

    Returns ((obj) => obj is {
        [X in string | number | symbol]: X extends P
            ? NonUndefined<T[X]>
            : T[X]
    })

      • (obj): obj is {
            [X in string | number | symbol]: X extends P
                ? NonUndefined<T[X]>
                : T[X]
        }
      • Parameters

        • obj: T

        Returns obj is {
            [X in string | number | symbol]: X extends P
                ? NonUndefined<T[X]>
                : T[X]
        }

Generated using TypeDoc