-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Which package is this bug report for?
discord.js
Issue description
I've discovered incorrect typings in some of the partial types. Particularly, the .toString() method supposedly always evaluates to "[object Object]", despite this never being the case during runtime.
Why I believe I'm correct:
<GuildMember>.toString()returns aUserMentionwhich is (ultimately) based on<GuildMember>.user.id<GuildMember>.idreturns<GuildMember>.user.id- The
idproperty is guaranteed to exist on all partial types (seePartializetype) - Therefore,
<PartialGuildMember>.user.idis also guaranteed to exist - That is to say:
PartialGuildMembers are always mentionable - Consequently,
<PartialGuildMember>.toString()should always yield a string like the non-partial variant does
During runtime, PartialGuildMember always has a .toString() method attached.
However, typescript-eslint (extending plugin:@typescript-eslint/strict-type-checked) tells me that the latter may evaluate to "[object Object]" (@typescript-eslint/no-base-to-string).
This problem also exists on other partial types. I have yet to look a bit further into this, but so far I've identified this to potentially be the case with User, Channel, MessageReaction and ThreadMember.
Code sample
/* eslint-disable @typescript-eslint/no-unused-vars */
import { GuildMember, PartialGuildMember } from "discord.js";
// No linting error here
function test1(member: GuildMember) {
console.log(`${member.toString()}`);
}
// Throws @typescript-eslint/no-base-to-string with typescript-eslint
function test2(member: PartialGuildMember) {
console.log(`${member.toString()}`);
}Versions
-
discord.js 14.13.0
-
Node.js 18.17.1
-
TypeScript 5.2.2
-
Windows 10 Pro N 22H2 Build 19045.3086 with Experience 1000.19041.1000.0
-
eslint 8.48.0
-
@types/node 18.17.1
-
@typescript-eslint/eslint-plugin 6.6.0
-
@typescript-eslint/parser 6.6.0
Issue priority
Low (slightly annoying)
Which partials do you have configured?
GuildMember
Which gateway intents are you subscribing to?
GuildMembers
I have tested this issue on a development release
0d40855.0