#never type unexcepted

1 messages ยท Page 1 of 1 (latest)

covert vault
narrow ivy
#

please don't show these massive files

#

!:mcve

silver wrenBOT
#
Deleted User 4b32c763#0396
`!n_n:mcve`:

MCVE
an example that is:

  • minimal - any code not related to your issue is removed
    (alternately, write a new snippet that demonstrates the same error)
  • complete - all the information relevant to your issue is in the question, or the code
    (a playground link that's properly erroring is enough)
  • verifiable - the example still demonstrates your issue
    read more on Stack Overflow
narrow ivy
#

use the playground if possible

covert vault
#

but if i don't someone will ask what's this or this

narrow ivy
#

im not seeing an if for your else

covert vault
#

Extends.ts:

export class CMDInteraction extends CommandInteraction {
    public client: PayBot;
    public options: CommandInteractionOptionResolver;
}


export class CompleteInteraction extends AutocompleteInteraction {
    public client: PayBot;
}
export class ContextInteraction extends MessageContextMenuCommandInteraction {
    public client: PayBot;
}```
narrow ivy
covert vault
#

class used in it

narrow ivy
covert vault
#

bruh

narrow ivy
#

you can just merge to the Base interface

#
declare module 'discord.js' {
  interface Base {
    client: <your Client class name>
  }
}
covert vault
#

idk what these words means, i just want my context menu handler work

narrow ivy
covert vault
narrow ivy
#

you have an else but no if before it

covert vault
#

that's the code

narrow ivy
#

it isn't though

covert vault
#

what ?

narrow ivy
#

oh bruh i see, code folding lmao; it's really not obvious in the screenshot (don't use screenshots)

#

this is why you don't randomly extend classes...

covert vault
#

that's why i sent the code

#

bro

narrow ivy
covert vault
#

no

narrow ivy
#

no. you're the asker. you have an obligation to provide a helpable question.

narrow ivy
#

use Interaction

#

done

covert vault
narrow ivy
#

i have no idea what that says, sorry

covert vault
#

yeah

#

just the ts(2687) error

narrow ivy
#

...yeah i give up if you can't be bothered to let us help

zealous fable
#

(it's sticky scroll)

covert vault
narrow ivy
#

is that why it's so horribly misaligned

covert vault
#

??

#

i'm giving you the error

#

i wasn't able to find doc for that error in my context

#

so i would appreciate if you can help me with it

zealous fable
#

@narrow ivy btw

#

that is not the error

#

here is a mcve

silver wrenBOT
zealous fable
#

!ts

silver wrenBOT
#
// 8<
import * as D from "discord.js";

function foo(i: D.CommandInteraction | D.AutocompleteInteraction | D.MessageContextMenuCommandInteraction) {
    if (i.isCommand()) {
          i;
//        ^? - (parameter) i: D.CommandInteraction<D.CacheType> | D.MessageContextMenuCommandInteraction<D.CacheType>
    } else if (i.isAutocomplete()) {
          i;
//        ^? - (parameter) i: D.AutocompleteInteraction<D.CacheType>
    } else if (i.isContextMenu()) {
//               ^^^^^^^^^^^^^
// Property 'isContextMenu' does not exist on type 'never'.
          i;
//        ^? - (parameter) i: never
    }
}
zealous fable
#

(with original discord.js types)

#

so it is not a problem with extending the classes

narrow ivy
#

yeah would've been a lot more obvious with the actual types

covert vault
#

didn't i gave you the classes ?

zealous fable
#

uh typo

zealous fable
#

it's the exact same error

#

sooooo

narrow ivy
narrow ivy
silver wrenBOT
covert vault
#

so stop saying i'm not listening

#

tf

zealous fable
narrow ivy
zealous fable
#

it's very clear why the never is happening

#

it's narrowing

#

it's always narrowing

#

*a bit of an overstatement

narrow ivy
#

lmao nice save

zealous fable
#

but imo it's not too hard to find the narrowing - assuming that it is the cause

#

!ts

silver wrenBOT
#

:warning: could not find any TypeScript codeblocks in the past 10 messages

zealous fable
#

:(

silver wrenBOT
zealous fable
#

!ts

silver wrenBOT
#
// 8<
import * as D from "discord.js";

function foo(i: D.CommandInteraction | D.AutocompleteInteraction | D.MessageContextMenuCommandInteraction) {
    if (i.isContextMenuCommand()) {
          i;
//        ^? - (parameter) i: D.MessageContextMenuCommandInteraction<D.CacheType> | D.ContextMenuCommandInteraction<D.CacheType>
    } else if (i.isCommand()) {
          i;
//        ^? - (parameter) i: D.CommandInteraction<D.CacheType>
    } else if (i.isAutocomplete()) {
          i;
//        ^? - (parameter) i: D.AutocompleteInteraction<D.CacheType>
    }
}
zealous fable
#

here's the solution

narrow ivy
#

isChatInputCommand is the proper typeguard if you want just the CommandInteraction (really ChatInputCommandInteraction)

covert vault
#

@zealous fable idk what all you're saying mean but i know both of u and @narrow ivy can help me. can u give me details for me to understand ?

zealous fable
covert vault
zealous fable
#

so the issue is that both ChatInputCommandInteraction and MessageContextMenuCommandInteraction are CommandInteraction

#

and isCommand catches the MessageContextMenuCommandInteraction

#

so it never reaches the i.isAutocomplete()

#

hence the never

covert vault
#

uu so what to do ?

zealous fable
#

instead of isCommand

covert vault
#

ok

#

and can you explain why that_guy told me to use this snippet ?

narrow ivy
#

so you can tell ts that you're using your own client rather than djs's

#

so you can access stuff on PayBot from guild.client, message.client, interaction.client, whatever

#

you don't need to make separate classes

covert vault
#

but using guild or smth else will result in some long and long lines of code to do something simple

narrow ivy
#

????

#

no this works everywhere

#

if you have a guild and you want your client, you can use guild.client

#

for example, in guildCreate, guildDelete, guildUpdate

#

or if you have a guildmember, you can do it too, like in guildMemberAdd

covert vault
#

look, this one is very long for simple task, not very readable

#

just for retrieveing a user from db

narrow ivy
#

that's readable

covert vault
#

not for me

narrow ivy
#

skill issue

covert vault
#

thx

#

very constructive

narrow ivy
#

it'll be worse if you don't have the extension

covert vault
#

what extension ?

narrow ivy
#

let me guess, you have interaction as one of your own classes here

covert vault
#

i don't get it

#

no, interaction is native

narrow ivy
#

doubt, Interaction#client.db doesn't exist

covert vault
#

yep, i precise interaction#client is PayBot

narrow ivy
#

exactly

#

so you have to do that for interactions, but also guilds and members and users and roles and channels separately if you want your PayBot

#

so now you have a bunch of classes that extend existing classes and just redeclare a single property

covert vault
#

why do i need for guilds ? wtf

narrow ivy
covert vault
#

but that don't work

narrow ivy
#

so you can actually use the Interaction that djs gives

covert vault
narrow ivy
#

and you got an error and you didn't tell me what it was

covert vault
#

bro

covert vault
#

i gave it

narrow ivy
#

im not psychic

covert vault
#

bro

narrow ivy
#

i can't read error codes like that, im not a robot ๐Ÿ’€

covert vault
#

u litteraly read that for screenshot and give me

narrow ivy
#

yes, and i still don't know what the error is

covert vault
#

ok

narrow ivy
#

you have the error right there, and you clearly understand the message since you have that language set?

covert vault
#

so don't tell me to add code if you don't know what's wrong with it

#

tf is wrong

narrow ivy
#

the code is fine, it's used in plenty of places

#

the context isn't

covert vault
#

..

narrow ivy
#

there's something wrong around it

#

and i don't know what that is if you don't tell me what's wrong...

#

im not going to go through the massive ts error code json when you can just tell me what it is...

covert vault
narrow ivy
#

im not

covert vault
#

like i litteraly told 5 times what it is

narrow ivy
#

you're literally just, refusing to say what the error message says?

covert vault
#

ts(2687) error

narrow ivy
#

i can't read french ๐Ÿ’€

#

i can't read error codes either ๐Ÿ’€

#

i've told you that already

covert vault
#

all declarations of client must have identic modifiers

narrow ivy
#

make it readonly or something, i don't remember

covert vault
#

...

#

where ? maybe more precise

narrow ivy
#

readonly client: PayBot

covert vault
#

"The next property declarations must have the same type. The 'client' property must have the type 'Client<true>', but here it has the type 'PayBot'.ts(2717)"

narrow ivy
#

have PayBot extend Client<true> instead of just Client

#

(which is Client<boolean> by default)

covert vault
#

still get the error

narrow ivy
#

bro why are your buttons so big ๐Ÿ’€

#

unrelated, but jesus christ lmao

covert vault
#

it's extension

narrow ivy
#

anyways, that's probably lag if nothing changed

narrow ivy
covert vault
#

don't work

#

same error

narrow ivy
#

is your PayBot overriding any properties or methods of Client

covert vault
#

no, just adding

#

and use super(options) to keep options from Client class

narrow ivy
#

seems to work for some people i've helped thonk