#parameters displaying as never instead of their types

26 messages · Page 1 of 1 (latest)

slow heart

https://tinyurl.com/tscplayground1

If you take a look at the typescript playground above, it shows that

(parameter) member: never
(parameter) action: never
(parameter) role: never

when they should be

(parameter) member: GuildMember & {
    user: User;
    permissions: Permissions;
}
(parameter) action: "add" | "remove"
(parameter) role: Role

I asked in the typescript discord as well but they couldn't find a solution and I tried to debug it myself and still couldnt find a solution. any help would be very appreciated.

outer otterBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
slow heart

(had to link shorten it because the natural playground link was too large to send without nitro)

cosmic pebble

It may possibly be due to you casting your data as const and I'm just guessing here without looking at everything else. Try typing it as ChatInputApplicationCommandData

slow heart

as ChatInputCommandInteractionData if this is what you are saying, it does nothing and its the same issue

cosmic pebble

Ok yeah, it should be as const if your goal is to correctly type the options. I am not so sure rn, I'll have to take a look at it again once I'm on pc. Perhaps wait for someone who can answer

slow heart
rain junco

Seems to work when I use satisfies ChatInputApplicationCommandData instead of as const

ocean plover

because yours doesn't distinguish whether the type allows choices or options

That's why

T extends {
  options: ReadonlyArray<ApplicationCommandOptionData>;
}

is true but

T extends {
  options: ReadonlyArray<CommandOption>;
}

isn't

ocean plover

and you could have stated that your TS post is still ongoing, as you're now getting feedback in two places. changing all your Array to ReadonlyArray fixes all your issues, but I'd still recommend using available types instead reinventing the wheel. Especially considering you were half complaining about having to do all of those to get typesafety

slow heart
slow heart
ocean plover

no, I was wrong that your type caused that issue because of that. the real cause is your missing readonly in several places, as already stated in your TS post

but using the existing type exported from discord.js instead of making another yourself is still advisable

slow heart

also with choices, they are formatted as an object with a name and value field

is this not extracting it properly? if i have a string option with choices it sets it as string but not specifically the "choice1" | "choice2" ...

ocean plover

and why it doesn't extract is because, again, in your helper type that does the extraction you're checking for extends Array<...> instead of ReadonlyArray

slow heart

i dont see where im doing extends Array

ocean plover

line 73 and 79

those responsible for extracting choices

slow heart

ah i see it, looks like its working perfectly