I've been developing a software application that utilizes WebSocket with the NodeJS ws package. My networking structure revolves around a module responsible for handling message reception and transmission. Given that I'm working with TypeScript, I wanted to leverage its type checking capabilities, which can be quite useful at times. Consequently, I created two types:
// networking.ts
export class Message {
constructor(
public request: string,
public params: Params) {}
}
export interface Params {
messageId?: number;
}
While this setup functions smoothly when only the messageId
parameter is needed, complications arise when I also need to include a nickname as a parameter. While I could simply add it to the existing Params
definition, I prefer not to burden the networking engine with knowledge of all possible parameters that may need to be sent (considering there are multiple parameters in play)...
Is there a way to achieve something like the following:
// profile-params.ts
export interface Params {
nickname:string;
}
// admin-params.ts
export interface Params {
authorizations: string[];
}
Thus enabling the merging of the Params
declaration? I explored the official documentation, but was unable to make it function across different files.
Thank you