underctrl-io / commandkit

Only focus on what matters - Let CommandKit handle your commands and events in your Discord.js projects!
https://commandkit.js.org
MIT License
86 stars 11 forks source link

CommandData typings #9

Closed feelthatvib3 closed 11 months ago

feelthatvib3 commented 11 months ago

Hello, I've recently bumped into an error while coding a simple command that accepts a string option.

(I removed name & description for the sake of focusing on the main problem here)

export const data: CommandData = {
    name: "",
    description: "",
    options: [
        {
            name: "",
            description: "",
            type: ApplicationCommandOptionType.String,
            required: true,
        },
    ],
};

Here it gives me an error:

Type 'ApplicationCommandOptionType.String' is not assignable to type 'ApplicationCommandOptionType.Subcommand | ApplicationCommandOptionType.SubcommandGroup'.

Looking at the CommandData type here I've noticed that it might be lacking APIApplicationCommandBasicOption in Array<APIApplicationCommandSubcommandOption | APIApplicationCommandSubcommandGroupOption>.

type CommandData = {
    name: string;
    description: string;
    type?: CommandType;
    name_localizations?: Partial<Record<LocaleString, string | null>>;
    description_localizations?: Partial<Record<LocaleString, string | null>>;
    dm_permission?: boolean;
    default_member_permissions?: string;
    nsfw?: boolean;
    options?: Array<APIApplicationCommandSubcommandOption | APIApplicationCommandSubcommandGroupOption>;
};

However, looking at the code in src/types/index.ts:

type BaseCommandData = {
    name: string;
    type?: CommandType;
    name_localizations?: Partial<Record<LocaleString, string | null>>;
    dm_permission?: boolean;
    default_member_permissions?: string;
    nsfw?: boolean;
};

type ChatInputCommandData = BaseCommandData & {
    type?: CommandType.ChatInput;
    description: string;
    description_localizations?: Partial<Record<LocaleString, string | null>>;
    options?: Array<APIApplicationCommandOption>;
};

type UserOrMessageCommandData = BaseCommandData & {
    type: CommandType.User | CommandType.Message;
};

export type CommandData = ChatInputCommandData | UserOrMessageCommandData;

You are actually using APIApplicationCommandOption which kind of covers all the types as the official discord.js documentation suggests.

Not exactly sure what causes the issue here, but I thought it would be good to report a problem.

notunderctrl commented 11 months ago

Version 0.1.2 fixes this issue. Thanks for pointing it out :)