Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing overrides for .toString() in partial types #9833

Closed
janparisek opened this issue Sep 13, 2023 · 1 comment · Fixed by #9835
Closed

Missing overrides for .toString() in partial types #9833

janparisek opened this issue Sep 13, 2023 · 1 comment · Fixed by #9835

Comments

@janparisek
Copy link
Contributor

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 a UserMention which is (ultimately) based on <GuildMember>.user.id
  • <GuildMember>.id returns <GuildMember>.user.id
  • The id property is guaranteed to exist on all partial types (see Partialize type)
  • Therefore, <PartialGuildMember>.user.id is 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

@janparisek
Copy link
Contributor Author

I'm already working on a fix.

@kodiakhq kodiakhq bot closed this as completed in #9835 Oct 10, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants