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

APIChannel types could be more "strict" #670

Open
cyyynthia opened this issue Dec 12, 2022 · 1 comment
Open

APIChannel types could be more "strict" #670

cyyynthia opened this issue Dec 12, 2022 · 1 comment
Labels

Comments

@cyyynthia
Copy link
Contributor

Issue description

A lot of the fields of APIChannel-related types are marked as optional, where in practice they are not for the given channel type.

Here's an example: for APIThreadChannel, the thread_metadata property is marked optional (which is according to Discord's documentation of the channel data object is correct) - however, I haven't seen any instance where for a thread channel this data was missing. For Group DMs, the owner_id field should always be present (including when the GDM is from an app), but is marked as optional.

This makes it harder to know to know which fields are consistently there, as the types tend to be overly conservative over marking these fields as optional. This also means additional unnecessary guards (or worse, some !) have to be added due to TypeScript rightfully emitting errors.

name is an example of property that has been strongly typed per-type, rather than using Discord's generic description of "optional, possibly null string". I feel like this should also be done for other properties.

Code sample

function isThreadLocked (thread: APIThreadChannel): boolean {
  // Error! thread_metadata might be undefined.
  return thread.thread_metadata.locked
}

async function getGdmOwnerUser (gdm: APIGroupDMChannel): Promise<APIUser> {
  // Error! owner_id might be undefined.
  return fetch(`.../users/${gdm.owner_id}`, { ... }).then((r) => r.json() as Promise<APIUser>)
}

Package version

0.37.22

Runtime

Node.js

Runtime version

v18.12.1

Priority this issue should have

Low (slightly annoying)

@cyyynthia cyyynthia added the bug label Dec 12, 2022
@vladfrangu
Copy link
Member

Be our guest to tackle this beast if you desire!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants