#never type unexcepted
1 messages ยท Page 1 of 1 (latest)
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
use the playground if possible
but if i don't someone will ask what's this or this
im not seeing an if for your else
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;
}```
yes, that's the point of an mcve, it's minimal but complete
class used in it
you don't need to do any of this.
bruh
you can just merge to the Base interface
declare module 'discord.js' {
interface Base {
client: <your Client class name>
}
}
idk what these words means, i just want my context menu handler work
#1066029216749080660 message
where ?
it isn't though
what ?
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...
and you expect me to read through 70 lines of code?
no
no. you're the asker. you have an obligation to provide a helpable question.
use this
get rid of this
use Interaction
done
i have no idea what that says, sorry
...yeah i give up if you can't be bothered to let us help
it's not folding
(it's sticky scroll)
i'm litteraly doing what you're trying to told me
??
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
!ts
// 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
}
}
(with original discord.js types)
so it is not a problem with extending the classes
yeah would've been a lot more obvious with the actual types
didn't i gave you the classes ?
uh typo
nope
it's the exact same error
sooooo
buddy i am not reading through that
i mean reading the code
i didnt read the code
yeah that's fair
it's very clear why the never is happening
it's narrowing
it's always narrowing
*a bit of an overstatement
lmao nice save
but imo it's not too hard to find the narrowing - assuming that it is the cause
!ts
:warning: could not find any TypeScript codeblocks in the past 10 messages
:(
!ts
// 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>
}
}
here's the solution
isChatInputCommand is the proper typeguard if you want just the CommandInteraction (really ChatInputCommandInteraction)
@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 ?
ok tbh this is probably better, yeah
where ?
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
uu so what to do ?
@covert vault
instead of isCommand
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
but using guild or smth else will result in some long and long lines of code to do something simple
????
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
look, this one is very long for simple task, not very readable
just for retrieveing a user from db
that's readable
not for me
skill issue
it'll be worse if you don't have the extension
what extension ?
let me guess, you have interaction as one of your own classes here
doubt, Interaction#client.db doesn't exist
yep, i precise interaction#client is PayBot
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
why do i need for guilds ? wtf
this is how you avoid all that
but that don't work
so you can actually use the Interaction that djs gives
and you got an error and you didn't tell me what it was
bro
im not psychic
bro
i can't read error codes like that, im not a robot ๐
u litteraly read that for screenshot and give me
yes, and i still don't know what the error is
ok
you have the error right there, and you clearly understand the message since you have that language set?
..
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...
bro, if you're joking or smth like it isn't funny
im not
like i litteraly told 5 times what it is
you're literally just, refusing to say what the error message says?
i can't read french ๐
i can't read error codes either ๐
i've told you that already
all declarations of client must have identic modifiers
make it readonly or something, i don't remember
readonly client: PayBot
"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)"
have PayBot extend Client<true> instead of just Client
(which is Client<boolean> by default)
it's extension
anyways, that's probably lag if nothing changed
yeah usually they aren't that big
even after reload
don't work
same error
is your PayBot overriding any properties or methods of Client
seems to work for some people i've helped 