getDescriptor

Commons
stable

Walks the prototype chain of an object and returns the first property descriptor found for the given key. Works across the full inheritance hierarchy, not just own properties.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

obj
required
any
The object (or instance) to inspect. The function walks up via Object.getPrototypeOf until the key is found or the chain ends.
key
required
PropertyKey
The property key to look for (string, number, or symbol).

API

Return value

The value returned by this util.

The first matching PropertyDescriptor, or undefined when the key is not found anywhere in the chain.

Usage

Examples

Ready-to-paste usage snippets.

Read a getter from a prototype

typescript