Fix type errors in extensions-slashcommands
| @@ -9,7 +9,8 @@ import { equalsIgnoreCaseAndAccents, isFalseBoolean, isTrueBoolean } from './uti | |||
| 9 | 9 | ||
| 10 | /** | 10 | /** |
| 11 | * @param {'enable' | 'disable' | 'toggle'} action - The action to perform on the extension | 11 | * @param {'enable' | 'disable' | 'toggle'} action - The action to perform on the extension |
| 12 | * @returns {(args: {[key: string]: string | SlashCommandClosure}, extensionName: string | SlashCommandClosure) => Promise<string>} | 12 | * @typedef {import('./slash-commands/SlashCommand.js').NamedArguments | import('./slash-commands/SlashCommand.js').NamedArgumentsCapture} NamedArgumentsAssignment |
| 13 | * @returns {(args: NamedArgumentsAssignment, extensionName: string | SlashCommandClosure) => Promise<string>} | ||
| 13 | */ | 14 | */ |
| 14 | function getExtensionActionCallback(action) { | 15 | function getExtensionActionCallback(action) { |
| 15 | return async (args, extensionName) => { | 16 | return async (args, extensionName) => { |
| @@ -20,7 +21,7 @@ function getExtensionActionCallback(action) { | |||
| 20 | return ''; | 21 | return ''; |
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | const reload = !isFalseBoolean(args?.reload); | 24 | const reload = !isFalseBoolean(args?.reload?.toString()); |
| 24 | const internalExtensionName = findExtension(extensionName); | 25 | const internalExtensionName = findExtension(extensionName); |
| 25 | if (!internalExtensionName) { | 26 | if (!internalExtensionName) { |
| 26 | toastr.warning(`Extension ${extensionName} does not exist.`); | 27 | toastr.warning(`Extension ${extensionName} does not exist.`); |
| @@ -186,8 +187,8 @@ export function registerExtensionSlashCommands() { | |||
| 186 | if (args?.state instanceof SlashCommandClosure) throw new Error('\'state\' argument cannot be a closure.'); | 187 | if (args?.state instanceof SlashCommandClosure) throw new Error('\'state\' argument cannot be a closure.'); |
| 187 | if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.'); | 188 | if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.'); |
| 188 | 189 | ||
| 189 | const action = isTrueBoolean(args?.state) ? 'enable' : | 190 | const action = isTrueBoolean(args?.state?.toString()) ? 'enable' : |
| 190 | isFalseBoolean(args?.state) ? 'disable' : | 191 | isFalseBoolean(args?.state?.toString()) ? 'disable' : |
| 191 | 'toggle'; | 192 | 'toggle'; |
| 192 | 193 | ||
| 193 | return await getExtensionActionCallback(action)(args, extensionName); | 194 | return await getExtensionActionCallback(action)(args, extensionName); |