diff --git a/demo.ts b/demo.ts index c648fc7..affb4d0 100644 --- a/demo.ts +++ b/demo.ts @@ -1,5 +1,6 @@ import { RPCServer, RPCSocket } from './Index' import { RPCExporter } from './src/Interfaces' +import { RPCInterface } from './src/Types' // TL;DR const echo = (text: string) => text @@ -175,17 +176,16 @@ interface IMyImplementation { getCallback: (callback:Function) => string } -type MyIfc = { - MyRPCGroup1: { - echo: IMyImplementation['echo'] - add: IMyImplementation['add'] - getAsync: IMyImplementation['getAsync'] - getCallback: IMyImplementation['getCallback'] +type IfcGenerator = { + [name in Name]: { + [key in keys] : Interface[key] } } +type MyIfc = IfcGenerator<"MyRPCGroup1", IMyImplementation> + class MyImplementation implements IMyImplementation, RPCExporter{ - //"X" as "X" syntax is required to satisfy the type system (as it assumed string) + //"X" as "X" syntax is required to satisfy the type system (as it assumes string) name = "MyRpcGroup11" as "MyRPCGroup1" //List the functions you declared in MyIfc diff --git a/test/Test.ts b/test/Test.ts index 1427a9a..3f8ed0c 100644 --- a/test/Test.ts +++ b/test/Test.ts @@ -38,7 +38,8 @@ function makeServer() { function triggerCallback(...messages: any[]): number { return subcallback.apply({}, messages) }, ] }], { - connectionHandler: (socket) => { }, + connectionHandler: (socket) => { + }, closeHandler: (socket) => { }, errorHandler: (socket, err) => { throw err } })