From 2c31443a0125eb0bfd833d601165a685a10ffc68 Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Tue, 7 Sep 2021 18:27:11 +0200 Subject: [PATCH] replaced undefined type with null in Parameter --- src/managers/ChatCommandManager.ts | 13 +++++++------ src/structures/Parameter.ts | 2 +- src/types/Parameter.ts | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/managers/ChatCommandManager.ts b/src/managers/ChatCommandManager.ts index 6eec14b..bf00e76 100644 --- a/src/managers/ChatCommandManager.ts +++ b/src/managers/ChatCommandManager.ts @@ -1,9 +1,10 @@ -import { CommandInteraction, CommandInteractionOption, Message } from "discord.js"; +import { CommandInteraction, Message } from "discord.js"; import { CommandNotFound, MissingParameterError } from "../errors"; -import { BooleanParameter, InputParameter, NullParameter, NumberParameter, ObjectParameter, Parameter, StringParameter } from "../structures/Parameter"; -import { CommandMessageStructure as ChatCommandInteractionData } from "../types/ChatCommand"; -import { ChatCommand } from "../structures/ChatCommand"; +import { BooleanParameter, InputParameter, NullParameter, NumberParameter, ObjectParameter, Parameter, StringParameter } from "../structures/Parameter.js"; +import { CommandMessageStructure as ChatCommandInteractionData } from "../types/ChatCommand.js"; +import { ChatCommand } from "../structures/ChatCommand.js"; import { CommandManager } from "./CommandManager.js"; +import { ParameterResolvable } from "../types/Parameter.js"; export class ChatCommandManager extends CommandManager { protected readonly _list: ChatCommand[] = []; @@ -99,7 +100,7 @@ export class ChatCommandManager extends CommandManager { const command = this.get(i.commandName); if (command) { if (command.parameters.length > 0) { - const argsRaw = i.options.data.map((a) => a.value?.toString() || ""); + const argsRaw = i.options.data.map((a) => a.value || null); const args = this.processRawInput(argsRaw, command.parameters); return { command: command, @@ -118,7 +119,7 @@ export class ChatCommandManager extends CommandManager { } } - private processRawInput(args: string[], schema: Parameter[]): InputParameter[] { + private processRawInput(args: ParameterResolvable[], schema: Parameter[]): InputParameter[] { return schema.map((p, i) => { if (!p.optional && !args[i]) { throw new MissingParameterError(p); diff --git a/src/structures/Parameter.ts b/src/structures/Parameter.ts index 1b1298e..a7265d3 100644 --- a/src/structures/Parameter.ts +++ b/src/structures/Parameter.ts @@ -95,7 +95,7 @@ export class StringParameter extends InputParameter { return; } } - super(parameter, value?.toString()); + super(parameter, value?.toString() || ""); } } diff --git a/src/types/Parameter.ts b/src/types/Parameter.ts index 8964519..0db6099 100644 --- a/src/types/Parameter.ts +++ b/src/types/Parameter.ts @@ -2,7 +2,7 @@ import { ObjectID } from "../structures/Parameter.js"; export type ParameterType = "string" | "boolean" | "number" | "user" | "role" | "channel" | "mentionable"; -export type ParameterResolvable = string | boolean | number | ObjectID | null | undefined; //remove "undefined" +export type ParameterResolvable = string | boolean | number | ObjectID | null; /** * @interface