Incorrect typings for `.toString()` in partials?

Alright, I'm not sure whether or not I've found an issue, so correct me if I'm wrong. - <GuildMember>.toString() is (ultimately) based on <GuildMember>.user.id - <PartialGuildMember>.user.id exists, since it's the only property to be guaranteed on partials - Consequently, <PartialGuildMember>.toString() should yield a string similar to the non-partial variant - However, ESLint tells me that the latter may evaluate to "[object Object]" (@typescript-eslint/no-base-to-string) Is there something I'm getting wrong? Is this intended behavior?
No description
24 Replies
d.js toolkit
d.js toolkitβ€’10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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! - βœ… Marked as resolved by OP
Unknown User
Unknown Userβ€’10mo ago
Message Not Public
Sign In & Join Server To View
NKN1396
NKN1396β€’10mo ago
Give me 15 minutes
Unknown User
Unknown Userβ€’10mo ago
Message Not Public
Sign In & Join Server To View
MrMythical
MrMythicalβ€’10mo ago
PartialGuildMember is a djs type
Unknown User
Unknown Userβ€’10mo ago
Message Not Public
Sign In & Join Server To View
MrMythical
MrMythicalβ€’10mo ago
Yes It's not in the docs because it's just a type
NKN1396
NKN1396β€’10mo ago
Yeah, that. TypeScript forces me to use it (for good reasons I suppose, unless I got something fundamentally wrong).
MrMythical
MrMythicalβ€’10mo ago
Do you use the GuildMember partial? (Check your client declaration)
NKN1396
NKN1396β€’10mo ago
- discord.js 14.13.0 & node 18.17.1 - It's a discord.js issue - No error stack trace, this is about typings - Code: Repo Line 22. Added Line 45 to illustrate the issue. Thank you for reopening! I thought clicking the "solved" button would mean I solved the questionnaire I got from the bot 🀣 Yup, I do use the GuildMember partial on client creation.
MrMythical
MrMythicalβ€’10mo ago
Idk why toString() is a different type, but I believe it would be fine for you to just use the userMention() function shrug userMention(member.id)
NKN1396
NKN1396β€’10mo ago
I mean, that'd be a workaround, but it still wouldn't change the fact that this causes TypeScript to throw an error for no good reason. Looking at the d.js code, I don't see how <PartialGuildMember>.toString() could ever evaluate to "[object Object]" in practice. I believe the interface PartialGuildMember extends Partialize<> part in line 6131 of the typings are at fault here. Ideally, toString() should not be axed during the "partialization". However, I'm not 100% certain if this is intended behavior (and I'm missing something). Otherwise I'd have started a PR or maybe even attempted a fix myself already.
MrMythical
MrMythicalβ€’10mo ago
Yeah, I checked that, don't know why it would mess up toString's typings Might need to look at it closer when I'm on my pc
NKN1396
NKN1396β€’10mo ago
Alright. Thanks for taking your time, by the way.
Danial
Danialβ€’10mo ago
What's your TypeScript version? I am trying to reproduce it with this code and no errors for me:
import { GuildMember, PartialGuildMember } from "discord.js"

function test1(member: GuildMember) {
console.log(`${member.toString()}`)
console.log(`<@${member.id}>`)
}

function test2(member: PartialGuildMember) {
console.log(`${member.toString()}`)
console.log(`<@${member.id}>`)
}
import { GuildMember, PartialGuildMember } from "discord.js"

function test1(member: GuildMember) {
console.log(`${member.toString()}`)
console.log(`<@${member.id}>`)
}

function test2(member: PartialGuildMember) {
console.log(`${member.toString()}`)
console.log(`<@${member.id}>`)
}
πŸŒΊπŸ‡«πŸ‡· Shigu :3 🌺
I could reproduce the ESLint error with this setup: package.json tsconfig.json .eslintrc.cjs file.ts However, no TypeScript errors.
Danial
Danialβ€’10mo ago
Ah, I see it now
πŸŒΊπŸ‡«πŸ‡· Shigu :3 🌺
It looks like an ESLint issue. I kept the same setup but replaced file.ts with this : https://pastebin.com/y6RfmkHQ. I started the bot and gave myself a role on a test server the bot is in. It received a partial guild member and I called .toString() on it which logs the expected user mention.
No description
πŸŒΊπŸ‡«πŸ‡· Shigu :3 🌺
Actually my IDE says the .toString() is coming from Object, so there might be somehting wrong with the types but it works somehow
NKN1396
NKN1396β€’10mo ago
Yeah, TypeScript seems to be fine. I think it assumes Node will implicitly add .toString() to all objects. It's only getting caught by ESLint (or more specifically the plugin typescript-eslint) with the strict-type-checked configuration (plugin:@typescript-eslint/strict-type-checked). 5.2.2
MrMythical
MrMythicalβ€’10mo ago
A djs contributor told me the problem is with Partialize. Apparently the & is in the wrong order (hopefully I understood that correctly kek
NKN1396
NKN1396β€’10mo ago
Oh, Partialize sounds familiar. I was looking into the typings yesterday, seeing if I could fix the issue and it absolutely baffled me. That is, because it's WAY above my TS expertise and I couldn't understand a single thing. And it certainly didn't help that the 3 generic type names N, M and E were non-descriptive. Is someone already looking into this, or should I open an issue on GH? Actually, maybe someone already opened an issue, let me check.
Deleted User
Deleted Userβ€’10mo ago
Same problem here, waiting for a fix
NKN1396
NKN1396β€’10mo ago
I’m already working on a fix. It’s almost done, but I’m still wrestling the build toolchain as my tests keep failing.
Want results from more Discord servers?
Add your server
More Posts