Problem
Subcommands keys aren't typechecked.
{
schema: new SlashCommandBuilder()
.setName('myCommand')
.addSubcommand((subcommand) =>
subcommand.setName('subcommand1').setDescription('do 1'),
)
.addSubcommand((subcommand) =>
subcommand
.setName('subcommand2')
.setDescription('do 2'),
)
.toJSON(),
handler: {
somethingNotLegit: async (interaction) => {},
anyKeyCanBeHere: async (interaction) => {},
// ^ ------------ Not legit
},
}
Solution
Override the type of schema with subcommands strings as const (or check if they aren't in the type already). Then retrieve the subcommands keys with a type helper.
Problem
Subcommands keys aren't typechecked.
Solution
Override the type of
schemawith subcommands strings as const (or check if they aren't in the type already). Then retrieve the subcommands keys with a type helper.