TS Error

export interface Command {
name?: string; // Command names are taken from file names
description: string;
type: ApplicationCommandType;
defaultPermissions?: PermissionResolvable;
options?: ApplicationCommandOptionData[];
run: (interaction: ECICInteraction) => void;
autocomplete?: (interaction: AutocompleteInteraction) => void;
}

public appCommands: Command[] = [];

public refreshCommands(): Promise<Collection<string, ApplicationCommand<{
guild: GuildResolvable;
}>>> {
return this.application.commands.set(this.appCommands.map(cmdObj => {
const command: ApplicationCommandDataResolvable = {
name: cmdObj.name as string,
type: cmdObj.type, // Type 'ApplicationCommandType' is not assignable to type 'ApplicationCommandType.ChatInput'.
defaultMemberPermissions: cmdObj.defaultPermissions || null,
dmPermission: false
};

if(cmdObj.type === ApplicationCommandType.ChatInput) {
command.description = cmdObj.description; // Property 'description' does not exist on type 'UserApplicationCommandData'.
command.options = cmdObj.options; // Property 'options' does not exist on type 'UserApplicationCommandData'.
}

return command;
}));
}
export interface Command {
name?: string; // Command names are taken from file names
description: string;
type: ApplicationCommandType;
defaultPermissions?: PermissionResolvable;
options?: ApplicationCommandOptionData[];
run: (interaction: ECICInteraction) => void;
autocomplete?: (interaction: AutocompleteInteraction) => void;
}

public appCommands: Command[] = [];

public refreshCommands(): Promise<Collection<string, ApplicationCommand<{
guild: GuildResolvable;
}>>> {
return this.application.commands.set(this.appCommands.map(cmdObj => {
const command: ApplicationCommandDataResolvable = {
name: cmdObj.name as string,
type: cmdObj.type, // Type 'ApplicationCommandType' is not assignable to type 'ApplicationCommandType.ChatInput'.
defaultMemberPermissions: cmdObj.defaultPermissions || null,
dmPermission: false
};

if(cmdObj.type === ApplicationCommandType.ChatInput) {
command.description = cmdObj.description; // Property 'description' does not exist on type 'UserApplicationCommandData'.
command.options = cmdObj.options; // Property 'options' does not exist on type 'UserApplicationCommandData'.
}

return command;
}));
}
15 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Syjalo
Syjalo9mo ago
Just extend your Command interface with ApplicationCommandData and don't do that unnecessary mappings
ethan<333
ethan<333OP9mo ago
wdym by unnecessary mappings?
Syjalo
Syjalo9mo ago
By extending with ApplicationCommandData you will be able to pass the appCommands array directly without mapping it.
ethan<333
ethan<333OP9mo ago
ah, how do i extend my interface with ApplicationCommandData? sorry im not the best with typescript haha
Syjalo
Syjalo9mo ago
Ok, you can't extend it, since ApplicationCommandData is a type, but you can do
type Command = ApplicationCommandData & {
run: () => void;
autocomplete?: () => void;
}
type Command = ApplicationCommandData & {
run: () => void;
autocomplete?: () => void;
}
ethan<333
ethan<333OP9mo ago
so i use this instead of importing Command from my types? i dont see why something so simple is this difficult, is it like this for everyone?
Syjalo
Syjalo9mo ago
You can export this type and use it in your command files
Syjalo
Syjalo9mo ago
And you'll be able to pass your array directly to set
No description
Syjalo
Syjalo9mo ago
You just need to understate how strict typing works
ethan<333
ethan<333OP9mo ago
im still getting these errors
No description
Syjalo
Syjalo9mo ago
Again, no need to map your commmands
ethan<333
ethan<333OP9mo ago
so i just return this.application.commands.set(this.appCommands)?
Syjalo
Syjalo9mo ago
Yes
ethan<333
ethan<333OP9mo ago
oh there's no errors now, why was i doing that mapping in the first place?
Want results from more Discord servers?
Add your server