* This method automatically checks if the prop is function or getter and behaves accordingly. * * @param object - The object to look up the getter function in its prototype chain. * @param prop - The property name for which to find the getter function. * @returns The getter function found in the
( object: T, prop: string )
| 286 | * @returns The getter function found in the prototype chain or a fallback function. |
| 287 | */ |
| 288 | function lookupGetter<T extends Record<string, any>>( |
| 289 | object: T, |
| 290 | prop: string |
| 291 | ): ReturnType<typeof unapply<any>> | (() => null) { |
| 292 | while (object !== null) { |
| 293 | const desc = getOwnPropertyDescriptor(object, prop); |
| 294 | |
| 295 | if (desc) { |
| 296 | if (desc.get) { |
| 297 | return unapply(desc.get); |
| 298 | } |
| 299 | |
| 300 | if (typeof desc.value === 'function') { |
| 301 | return unapply(desc.value); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | object = getPrototypeOf(object); |
| 306 | } |
| 307 | |
| 308 | function fallbackValue(): null { |
| 309 | return null; |
| 310 | } |
| 311 | |
| 312 | return fallbackValue; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Like lookupGetter, but for accessor properties only, and returns null |
no test coverage detected