Skip to content

Conversation

@WhatCats
Copy link
Contributor

@WhatCats WhatCats commented Nov 20, 2025

Problem

At the moment methods like GuildMemberManager:fetch that have an optional string parameter are doing a falsy check for if the parameter was omitted. But consider the following typescript code:

const id: string = ""
const member: GuildMember = await guild.members.fetch(id)

According to the typings member should be a GuildMember but its actually a Collection<Snowflake, GuildMember> because the empty string is falsy (this is why we love JS).

My Suggestion

Do more exact undefined/null checks.
(I might not have found every place this is an issue)

@vercel
Copy link

vercel bot commented Nov 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
discord-js Skipped Skipped Nov 20, 2025 10:44pm
discord-js-guide Skipped Skipped Nov 20, 2025 10:44pm

@vercel vercel bot temporarily deployed to Preview – discord-js November 20, 2025 22:40 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 20, 2025 22:40 Inactive
@WhatCats WhatCats force-pushed the fix/typing-mismatch branch from 16f28a2 to 847f9d3 Compare November 20, 2025 22:43
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 20, 2025 22:44 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js November 20, 2025 22:44 Inactive
@Jiralite Jiralite added this to the discord.js 15.0.0 milestone Nov 28, 2025
@almeidx
Copy link
Member

almeidx commented Dec 1, 2025

Personally, I think this is a step in the right direction. However, I don't think this change alone is enough, as it will potentially bring different issues. For instance, passing an empty string to RoleManager#fetch() will now make a request to the Get Guild Roles endpoint, but through the Get Guild Role path internally. This will mean the endpoint will return a different body than expected, which might create worse errors that are harder to pinpoint.

To fix that, we should make further changes here. For instance, modifying the resolveId() method of managers to return null for empty strings. This solves the issue I mentioned in most places, but there are still some places that do not make use of this method (e.g., the RoleManager), so those places would have to be modified to make use of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants