Skip to content

Commit e71f2c9

Browse files
committed
fix: add default type for slash generic type
1 parent a8036d7 commit e71f2c9

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/define.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ export const defineEvent: DefineEvent & DefineEventWithOptions = <
5959
}
6060

6161
export const defineCommand = <
62-
Slash extends boolean,
62+
K extends boolean = boolean,
6363
T extends ArgsDef = ArgsDef
6464
>(
65-
options: CommandOptions<Slash> & { slash?: Slash; args?: T },
66-
execute: CommandExecute<Slash, T>
67-
): HarmonixCommand<Slash, T> => {
65+
options: CommandOptions<K> & { slash?: K; args?: T },
66+
execute: CommandExecute<K, T>
67+
): HarmonixCommand<K, T> => {
6868
return { options, execute }
6969
}
7070

src/resolve.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import jiti from 'jiti'
22
import { dirname } from 'pathe'
33
import { filename } from 'pathe/utils'
44
import type {
5-
ArgsDef,
65
CommandOptions,
76
ContextMenuOptions,
87
EventOptions,
@@ -46,14 +45,14 @@ export const resolveEvent = (
4645
export const resolveMessageCommand = (
4746
cmd: HarmonixCommandInput,
4847
harmonixOptions: Harmonix['options']
49-
): HarmonixCommand<boolean, ArgsDef> => {
48+
): HarmonixCommand => {
5049
if (typeof cmd === 'string') {
5150
const _jiti = jiti(harmonixOptions.rootDir, {
5251
interopDefault: true
5352
})
5453
const _cmdPath = _jiti.resolve(cmd)
55-
const command = _jiti(_cmdPath) as HarmonixCommand<boolean, ArgsDef>
56-
const options: CommandOptions<boolean> = {
54+
const command = _jiti(_cmdPath) as HarmonixCommand
55+
const options: CommandOptions = {
5756
name: command.options.name || filename(_cmdPath).split('.')[0],
5857
category: command.options.category || filename(dirname(_cmdPath)),
5958
slash: command.options.slash || filename(_cmdPath).endsWith('.slash'),

src/types/commands.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,11 @@ interface CommandContext<T extends ArgsDef = ArgsDef> {
138138
args: ParsedArgs<T>
139139
}
140140

141-
export type CommandOptions<Slash extends boolean> = Slash extends true
141+
export type CommandOptions<K extends boolean = boolean> = K extends true
142142
? SlashCommandOptions
143143
: MessageCommandOptions
144144

145-
export type MessageOrInteraction =
146-
| Message
147-
| ChatInputCommandInteraction
145+
export type MessageOrInteraction = Message | ChatInputCommandInteraction
148146

149147
type ExecuteArgument<Slash extends boolean> = Slash extends true
150148
? ChatInputCommandInteraction
@@ -161,12 +159,12 @@ export type CommandExecute<
161159
context: CommandContext<T>
162160
) => void
163161

164-
export type HarmonixCommandInput = string | HarmonixCommand<boolean, ArgsDef>
162+
export type HarmonixCommandInput = string | HarmonixCommand
165163

166164
export interface HarmonixCommand<
167-
Slash extends boolean,
165+
K extends boolean = boolean,
168166
T extends ArgsDef = ArgsDef
169167
> {
170-
options: CommandOptions<Slash>
171-
execute: CommandExecute<Slash, T>
168+
options: CommandOptions<K>
169+
execute: CommandExecute<K, T>
172170
}

0 commit comments

Comments
 (0)