( target: Value<T>, partial: U, )
| 60 | * Useful when you want to override or extend behavior without fully copying/merging objects. |
| 61 | */ |
| 62 | export function overlayProxy<T extends object, U extends object>( |
| 63 | target: Value<T>, |
| 64 | partial: U, |
| 65 | ): U & Omit<T, keyof U> { |
| 66 | const proxy = new Proxy(typeof target === 'function' ? partial : target, { |
| 67 | get(_, prop) { |
| 68 | const targetValue = prop in partial |
| 69 | ? partial |
| 70 | : value(target) |
| 71 | |
| 72 | const v = Reflect.get(targetValue, prop) |
| 73 | return typeof v === 'function' |
| 74 | ? v.bind(targetValue) // .bind is required for async generator or iterator |
| 75 | : v |
| 76 | }, |
| 77 | has(_, prop) { |
| 78 | return Reflect.has(partial, prop) || Reflect.has(value(target), prop) |
| 79 | }, |
| 80 | }) |
| 81 | |
| 82 | return proxy as any |
| 83 | } |
no outgoing calls
no test coverage detected