blokur / grpc-ts-demo

🎵 Demo of a gRPC client and server implementation in TypeScript
MIT License
124 stars 30 forks source link

Changed SongServer to use interface types. #18

Open sjohnsonaz opened 2 years ago

sjohnsonaz commented 2 years ago

The implementation of ISongServer required explicitly defined types for call and callback parameters. This seems to be the case if you create a class implementing the interface. TypeScript cannot detect the correct parameter types, and so they have to be declared.

Instead, if you directly implement the interface with an object, TypeScript will infer all of the function types. So now you don't have to declare any parameter types. Here I just returned it from a function for simplicity.