Library API
    Preparing search index...

    Function hasOwn

    • Checks whether an object possesses a specific own property, unwrapping Proxies if present. Safe against null, undefined, and non-object primitives.

      Type Parameters

      • K extends PropertyKey

      Parameters

      • obj: unknown

        The target object to inspect

      • key: K

        The property key to test

      Returns boolean

      True if the unwrapped target possesses key as an own property

      if (hasOwn(config, 'timeZone')) { ... }
      
    • Asserts that an object possesses a specific own property whose value matches at least one of the specified type tags (case-insensitive, e.g. 'string', 'String', 'Number') or predicate functions. Safe against null, undefined, and non-object primitives.

      Type Parameters

      • K extends PropertyKey
      • G extends AnyGuard[]

      Parameters

      • obj: unknown

        The target object to inspect

      • key: K

        The property key to verify

      • ...guards: [...G[]]

        One or more type tags or predicate functions

      Returns obj is Record<K, ResolveTypeGuards<G>>

      True if the target possesses the own property and its value satisfies at least one guard

      if (hasOwn(config, 'timeout', 'number')) {
      config.timeout.toFixed();
      }
      if (hasOwn(err, 'code', isString, isNumber)) {
      console.log(err.code);
      }