@rbxts/expect > getNearestDefinedProxy
getNearestDefinedProxy() function
Finds the nearest proxy in the hierarchy that has a non null value, if any.
Signature:
declare function getNearestDefinedProxy<T = unknown, R = unknown>(proxy: Proxy<T>): Proxy<R> | undefined;
Parameters
Parameter | Type | Description |
---|---|---|
proxy | Proxy<T> | The child to start the search from. |
Returns:
Proxy<R> | undefined
The closest proxy that has a valid (non null) value, or undefined if all proxies have null values.
Example
const person = {
name: "Daymon",
child: {
name: "Michael"
}
}
withProxy(person, (proxy) => {
// assume this is valid typescript
const greatGrandChild = proxy.child.child.child;
expect(getNearestDefinedProxy(greatGrandChild)).to.deepEqual(person.child);
});