Type safe Slash Commands Options ?
Hi there, I can't seem to find a way to add Type Safe options to a Slash command. See Example:
I have a Type called
type Difficulty = 'easy' | 'medium' | 'hard'
and functions that expect this type. But the interaction.options.getString('difficulty', false)
method simply returns string
. Which means I need to add as Difficulty
to it. And I feel like it defeats a little bit the purpose of TypeScript when I do this.
So I was wondering if there was a better way to handle this, or should I just rely on Runtime checking ?
Thanks ❤️1 Reply
You'll have to cast it. Discordjs doesn't offer a way to make it type safe directly.
Just add
as Difficulty