diff --git a/src/messaging/layer2/InjectMessaging.ts b/src/messaging/layer2/InjectMessaging.ts index 5b14346..a62a692 100644 --- a/src/messaging/layer2/InjectMessaging.ts +++ b/src/messaging/layer2/InjectMessaging.ts @@ -6,7 +6,7 @@ class InjectMessaging { l1protocol?: Layer1Protocol //类实例 methods?: { - [key: string]: (params: any, context: MethodContext) => Promise + [K in AllInjectMessages['method']]: (params: Extract['params'], context: MethodContext) => Promise } debug = (...args: any[]) => { @@ -23,7 +23,7 @@ class InjectMessaging { // message: 'Target Error: ' + req.target, // }) - const method = this.methods?.[req.method] + const method = this.methods?.[req.method as keyof typeof this.methods] if (method != null) { return method(req.params, { from: req.from,