Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/src/utilities/panic-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,5 +28,5 @@ export function panicProxy(module: any) {
},
};

return new Proxy(module, proxyHandler);
return new Proxy<T>(module, proxyHandler);
}