mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-30 23:38:12 +08:00
Add proper type annotations for panicProxy (#378)
This commit is contained in:
committed by
Keavon Chambers
parent
225b46300d
commit
736d611812
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
// Import this function and chain it on all `wasm` imports like: const wasm = import("@/../wasm/pkg").then(panicProxy);
|
// 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
|
// 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 = {
|
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);
|
const targetValue = Reflect.get(target, propKey, receiver);
|
||||||
|
|
||||||
// Keep the original value being accessed if it isn't a function or it is a class
|
// 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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user