jty
    Preparing search index...

    Function hasOwnPath

    • Similar to hasPath but only works for own properties (not inherited properties)

      Type Parameters

      • K extends readonly PropertyKey[]

      Parameters

      • x: unknown

        a value that may possibly have some properties

      • ...propNames: readonly [K]

        one or more property names

      Returns x is DeepRecord<K, object>

      const x = { foo: { bar: { baz: undefined }}}
      hasOwnPath(x, 'foo', 'bar') => true
      hasOwnPath(x, 'foo', 'bar', 'baz') => true
      hasOwnPath(x, 'foo', 'hello', 'baz') => false

      // Unlike hasPath, it does not follow inherited properties
      const obj = { a: Object.create({ b: 1 }) }
      hasOwnPath(obj, 'a', 'b') => false