Created
April 2, 2021 02:36
-
-
Save ebeloded/f4a79a3cdf17a38aca299abe7c70d328 to your computer and use it in GitHub Desktop.
proxify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function proxify<T extends Object>(promise: Promise<T>): T { | |
const proxy = (path: Array<string> = []) => | |
new Proxy(() => {}, { | |
get: (_target, prop: string) => proxy([...path, prop]), | |
apply: (_, _this, argumentsList) => | |
promise.then((resolvedAPI) => | |
path | |
.reduce<any>((p, c) => p[c], resolvedAPI) | |
.apply(_this, argumentsList), | |
), | |
}) | |
return proxy() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment