Chatgpt helped me solving it:
I see. To achieve the structure you described with different games and different modes for each game, you can define a more complex set of interfaces and types. Here's how you can do it:
interface GameMode {
[key: string]: {
choices?: Record<string, any>;
scoreboard?: Record<string, any>;
[customProperty: string]: any;
};
}
interface GameModesByGame {
[game: string]: GameMode;
}
const gameModesEssentialSchemas: GameModesByGame = {
rps: {
classic: {
choices: {},
scoreboard: {}
},
differentMode: {
choices: {},
scoreboard: {},
diffProp: {}
}
},
ticTacToe: {
classic: {
randomprop: {}
},
differentMode: {
diffprop: {}
}
}
};
In this example, I've defined two interfaces: GameMode which represents a single game mode with optional properties, and GameModesByGame which represents a collection of game modes organized by game names.
You can then use these interfaces to annotate the gameModesEssentialSchemas object. The choices and scoreboard properties are common to all game modes, while any additional custom properties specific to a game mode can be added.
With this structure, TypeScript will be able to infer the types correctly when you access properties within the gameModesEssentialSchemas object based on the game and mode names.