Weird bug (?) with typescript and SlashCommandBuilders
I've ran into a weird issue with ts and SlashCommandBuilders
5 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.(copied from #djs-help-v14 )
https://bork.treble-is-fluffy.gay/floof69c30ca6.png
I'm getting this ts error with the following code. Whenever i add another options it goes away and i dont really have a clue what is going on since i just typed it as SlashCommandBuilder.
Now, this also happens with commands that have sub commands
`
To declare the data type use
Pick<SlashCommandBuilder, 'name' | 'toJSON'>
and other properties you actually need.i maybe should've used pastebin
ah
that fixes it indeed, still weird though that changing the position of .setDMPermissions solved it in my previous code
Changing the position of
#setDMPermissions()
"solved" it before because the type check you had in place was for a SlashCommandBuilder
and it seems that setting the DM permissions after a slash command option removes the omitted generic from the instance. As Syjalo already pointed out, adding a generic to account for this in your check removes the issue all together as it allows for this omitted generic to pass the type check as well as a regular SlashCommandBuilder
instance :P