#Workaround for correlated union issue?

27 messages · Page 1 of 1 (latest)

winged parcelBOT
#
daniellwdb#0

Preview:```ts
import {
Awaitable,
ClientEvents,
Events,
Client,
} from "discord.js"

declare const client: Client

interface Event<T extends keyof ClientEvents> {
name: T
execute(
...args: [...args: ClientEvents[T], str: string]
): Awaitable<void>
}

export function createEvent<
T extends keyof ClientEvents

(event: Event<T>)
...```

hollow needle
#

Any idea if it's possible to work around this error without ts-ignore?

winged parcelBOT
#
littlelily#0

Preview:```ts
import {
Awaitable,
ClientEvents,
Events,
Client,
} from "discord.js"

declare const client: Client

interface Event<T extends keyof ClientEvents> {
name: T
once: boolean
execute(
...args: [...args: ClientEvents[T], str: string]
): Awaitable<void>
...```

meager gorge
#

uh

#

I can’t quite see it well since i’m on mobile @rustic gate buy that still looks like correspondence problem to me

rustic gate
#

well it compiles

meager gorge
#

it’s just bypassed now by narrowing

rustic gate
#

yeah without the generic constraint in the forEach it doesnt work, so you're probably right

#

also I really wish there was a good mobile version of ts playground

hollow needle
#

Huh is this a good solution?

rustic gate
#

it's basically what I do in my TS discord bot

#

define a const array of events/commands and iterate over them (dont use an object cause Object.entries sucks)

hollow needle
#

Interesting.. Thanks! Can I get a repo link to see how you've approached other stuff like inferring command options?

#

Because that's a bit pain of a pain for me still

#

Also this is why I use an object, this way I don't have to mutate some top level array and export it

winged parcelBOT
#
littlelily#0

Preview:```ts
// commands/index.ts
import { ChatInputCommandInteraction, SlashCommandBuilder, SlashCommandSubcommandsOnlyBuilder } from "discord.js"

export type Command = {
data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup"> | SlashCommandSubcommandsOnlyBuilder,
...```

rustic gate
#

dont have a repo for that yet sorry

hollow needle
rustic gate
#

huh? they infer just fine cause i'm using the SlashCommandBuilder rather than using a plain object like in your example

hollow needle
#

Oh yes but I mean where you fetch them

rustic gate
#

wdym?

hollow needle
rustic gate
#

ah right

hollow needle
rustic gate
#

between the command data and the handler

hollow needle
#

Yea

#

If you don't mind using objects instead of builders you can use that code 😅 still trying to figure out the deepnested intellisense lacking but it's not that big of a deal I guess