Vinyl
    Preparing search index...

    Type Alias IsPropertyOptional<U, P>

    IsPropertyOptional: AnyRecord extends Pick<U, P> ? true : false

    Determines whether a property P of object type U is declared as optional.

    This checks whether the {} type (an empty object) is assignable to Pick<U, P>. In TypeScript, this is true only when P is marked optional using the ? modifier in the type definition.

    Importantly, this detects actual optionality rather than checking whether the property's type includes undefined. For example:

    type A = { x?: string };               // optional
    type B = { x: string | undefined }; // required but allows undefined

    IsPropertyOptional<A, "x"> // true
    IsPropertyOptional<B, "x"> // false

    Type Parameters

    • U

      The object type containing the property.

    • P extends keyof U

      The key of the property to test.

    true if P is an optional property, otherwise false.