I'm trying to merge namespace members across modules. I used to have all of them in a single file, but they're getting pretty big, since their main purpose is to correctly type all of my game packets.
I tried the code below, but when I hover over the Event type, it says never. TypeScript isn't properly extending anything and I have no idea what's the proper way to do this.
index.ts
export * from './Actions.js';
export * from './Items.js';
export * from './Chat.js';
export * from './Flock.js';
export * from './Io.js';
export * from './Items.js';
export * from './Join.js';
export * from './Prompt.js';
export namespace Client {
interface Packets {};
export type Event = keyof Packets;
export type Payload<E extends Event> = Packets[E];
export namespace Events {};
export namespace Payloads {};
}
Chat.ts
export namespace Client {
export interface Packets {
[Events.Chat.MESSAGE]: Payloads.Chat.Message;
[Events.Chat.MESSAGE_FAIL]: Payloads.Chat.MessageFail;
}
export namespace Events.Chat {
export const MESSAGE = 'chat:message';
export const MESSAGE_FAIL = 'chat:message-fail';
}
export namespace Payloads.Chat {
export interface Message {
id: number;
message: string;
}
export interface MessageFail {
message: string;
}
}
}