浏览代码

Before PioSocket dropin replacement

master
peter 4 年前
父节点
当前提交
f5fa51bef5
共有 2 个文件被更改,包括 9 次插入8 次删除
  1. 7
    7
      demo.ts
  2. 2
    1
      test/Test.ts

+ 7
- 7
demo.ts 查看文件

@@ -1,5 +1,6 @@
1 1
 import { RPCServer, RPCSocket } from './Index'
2 2
 import { RPCExporter } from './src/Interfaces'
3
+import { RPCInterface } from './src/Types'
3 4
 
4 5
 // TL;DR
5 6
 const echo = (text: string) => text
@@ -175,17 +176,16 @@ interface IMyImplementation {
175 176
     getCallback: (callback:Function) => string
176 177
 }
177 178
 
178
-type MyIfc = {
179
-    MyRPCGroup1: {
180
-        echo: IMyImplementation['echo']
181
-        add: IMyImplementation['add']
182
-        getAsync: IMyImplementation['getAsync']
183
-        getCallback: IMyImplementation['getCallback']
179
+type IfcGenerator<Name extends string, Interface, keys extends keyof Interface = keyof Interface> = {
180
+    [name in Name]: {
181
+        [key in keys] : Interface[key]
184 182
     }
185 183
 }
186 184
 
185
+type MyIfc = IfcGenerator<"MyRPCGroup1", IMyImplementation>
186
+
187 187
 class MyImplementation implements IMyImplementation, RPCExporter<MyIfc>{
188
-    //"X" as "X" syntax is required to satisfy the type system (as it assumed string)
188
+    //"X" as "X" syntax is required to satisfy the type system (as it assumes string)
189 189
     name = "MyRpcGroup11" as "MyRPCGroup1"
190 190
 
191 191
     //List the functions you declared in MyIfc

+ 2
- 1
test/Test.ts 查看文件

@@ -38,7 +38,8 @@ function makeServer() {
38 38
             function triggerCallback(...messages: any[]): number { return subcallback.apply({}, messages) },
39 39
         ]
40 40
     }], {
41
-        connectionHandler: (socket) => { },
41
+        connectionHandler: (socket) => {
42
+        },
42 43
         closeHandler: (socket) => { },
43 44
         errorHandler: (socket, err) => { throw err }
44 45
     })

正在加载...
取消
保存