Add proper type annotations for panicProxy (#378)

This commit is contained in:
Christian Authmann 2021-09-14 00:39:18 +02:00 committed by Keavon Chambers
parent 225b46300d
commit 736d611812

View file

@ -2,9 +2,9 @@
// Import this function and chain it on all `wasm` imports like: const wasm = import("@/../wasm/pkg").then(panicProxy);
// This works by proxying every function call wrapping a try-catch block to filter out redundant and confusing `RuntimeError: unreachable` exceptions sent to the console
export function panicProxy(module: any) {
export function panicProxy<T extends object>(module: T): T {
const proxyHandler = {
get(target: any, propKey: any, receiver: any) {
get(target: T, propKey: string | symbol, receiver: any): any {
const targetValue = Reflect.get(target, propKey, receiver);
// Keep the original value being accessed if it isn't a function or it is a class
@ -28,5 +28,5 @@ export function panicProxy(module: any) {
},
};
return new Proxy(module, proxyHandler);
return new Proxy<T>(module, proxyHandler);
}