@jossmac/lil-libs
    Preparing search index...

    Function hasKey

    • Narrows an unknown key to a known key of the object.

      • T extends object
      • object: T

        Object whose own properties to check.

      • key: PropertyKey

        Unknown key to test.

      true when key is an own property of object, narrowing it to keyof T; false for inherited or absent keys.

      const obj = { foo: 1, bar: "hello" };
      declare const key: string;

      if (hasKey(obj, key)) {
      obj[key];
      // ^? number | string
      }