I am building a software that uses WebSocket with the package NodeJS ws. I organised my networking around a module that is charged of receiving and sending the messages. Because i am using TypeScript, I want to use the type checking which can be pretty handy sometimes. So I constructed two types:
// networking.ts
export class Message {
constructor(
public request: string,
public params: Params) {}
}
export interface Params {
messageId?: number;
}
This works fine as long as I am only required to use messageId as a parameter. But what if I need to also send a nickname as a parameter ? I could add it to the Params definition but I don't want the networking engine to bother to know all the different parameters that can be sent (you can imagine that I have actually more than one parameter to send)...
Is there a way to do something like:
// profile-params.ts
export interface Params {
nickname:string;
}
// admin-params.ts
export interface Params {
authorizations: string[];
}
Such that in the end, the declaration of Params can be merged ? I looked at the official documentation but it can't make it work on different files.
Thanks