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 toolkit10mo 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
Syjalo10mo ago
Just extend your Command interface with ApplicationCommandData and don't do that unnecessary mappings
jacob
jacobOP10mo ago
wdym by unnecessary mappings?
Syjalo
Syjalo10mo ago
By extending with ApplicationCommandData you will be able to pass the appCommands array directly without mapping it.
jacob
jacobOP10mo ago
ah, how do i extend my interface with ApplicationCommandData? sorry im not the best with typescript haha
Syjalo
Syjalo10mo 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;
}
jacob
jacobOP10mo 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
Syjalo10mo ago
You can export this type and use it in your command files
Syjalo
Syjalo10mo ago
And you'll be able to pass your array directly to set
No description
Syjalo
Syjalo10mo ago
You just need to understate how strict typing works
jacob
jacobOP10mo ago
im still getting these errors
No description
Syjalo
Syjalo10mo ago
Again, no need to map your commmands
jacob
jacobOP10mo ago
so i just return this.application.commands.set(this.appCommands)?
Syjalo
Syjalo10mo ago
Yes
jacob
jacobOP10mo ago
oh there's no errors now, why was i doing that mapping in the first place?

Did you find this page helpful?