devtypes - v1.1.0
    Preparing search index...

    Type Alias HasOptionalProperty<T, K>

    HasOptionalProperty: K extends keyof T
        ? {} extends Pick<T, K> ? true : false
        : false

    Test if an object has an optional property.

    Type Parameters

    • T

      The object type

    • K extends PropertyKey

      The property key to check

    1.1.0

    Returns true only for properties declared with ?. Does not consider union types that include undefined.

    type Obj = { a: string; b?: number; c: number | undefined };
    type IsOpt_b = HasOptionalProperty< Obj, 'b' >; // true
    type IsOpt_c = HasOptionalProperty< Obj, 'c' >; // false