Skip to content
Functionutilsv0.8.17

hasKeys

Checks that the specified nested keys exist on a possibly distributed union object and are not null or undefined, narrowing the object type to reflect those keys with their types from the original union.

hasKeys<Obj, Keys>(
    obj: Obj,
    keys: Keys[]
): obj is Obj &
    UnionToIntersection<
        Keys extends unknown
            ? PathToObj<
                  Keys,
                  UnionToIntersection<
                      NonNullable<DeepGet<Obj, Keys>>
                  >
              >
            : never
    >

Obj

Obj

Keys

Keys

obj

obj: Obj

keys

keys: Keys[]

An array of dot-notation paths to check.