Discord.js: MessageStore contains incorrect type

Created on 30 Jul 2019  Â·  1Comment  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:

  1. The Message class supposedly contains a reactions property of type ReactionStore<Snowflake, MessageReaction>
  2. The fetchPinned method is capable of adding its incomplete Message objects (no reactions property) to the cache
  3. The MessageStore is typed as a DataStore containing Messages

MessageStore actually contains a different type;

interface EmptyReactionStore extends ReactionStore {
  get(...args: any[]): undefined;
}
interface PartialMessage extends Message {
  reactions: EmptyReactionStore
}

To resolve this, we can either actually change the type (I'm against this), avoid caching the results of fetchPinned, or return complete message objects from fetchPinned (And maybe other similar routes?)
Include a reproducible code sample here, if possible:

// Represented using typescript - source is the docs.
const messages = await channel.fetchPinned()
type A = typeof messages.first().reactions // ReactionStore
type B = typeof channel.get("id of pinned message").reactions // ReactionStore

Further details:

  • discord.js version: 1.12
  • Node.js version: N/A
  • Operating system: N/A
  • Priority this issue should have – please be realistic and elaborate if possible:
    High - the library does not function as documented, and this shouldn't be too hard to fix. The only decision to make is how to got about it.
  • [x] I have also tested the issue on latest master, commit hash: 53722b47c1d646a23f4eb422c0256eaef699383b
unverified bug

Most helpful comment

I'm not sure why this issue includes a new type for empty reaction stores, since all get method calls always have the option to return undefined anyway. The existing types are correct as far as I can see; an empty store just has the unique situation of having every get call return undefined rather than only some; this does not require a redefinition of its type.

You can easily disable the caching features on MessageStore#fetchPinned by passing false to the method, so I somewhat disagree with the priority on this since it's a pretty minor issue.

https://github.com/discordjs/discord.js/blob/53722b47c1d646a23f4eb422c0256eaef699383b/src/stores/MessageStore.js#L77-L83

I also disagree that these can be considered "partial": the message reactions property is documented as nullable from Discord, so according to the API this is a full and valid message. That being said, there should exist some functionality for bypassing the cache to fetch the message from the API. This is currently only possible if the message is actually partial (i.e. is missing documented non-null properties) and is likely an issue for other API objects.

I am very much against returning "complete" objects from either this endpoint or others; this opens a very large area for subtle bugs since we'd have to verify that every endpoint we hit returns whatever we consider to be a "complete" object. It also requires some magic from Discord.js to make it happen (i.e. extra API calls), which users might not be expecting.

>All comments

I'm not sure why this issue includes a new type for empty reaction stores, since all get method calls always have the option to return undefined anyway. The existing types are correct as far as I can see; an empty store just has the unique situation of having every get call return undefined rather than only some; this does not require a redefinition of its type.

You can easily disable the caching features on MessageStore#fetchPinned by passing false to the method, so I somewhat disagree with the priority on this since it's a pretty minor issue.

https://github.com/discordjs/discord.js/blob/53722b47c1d646a23f4eb422c0256eaef699383b/src/stores/MessageStore.js#L77-L83

I also disagree that these can be considered "partial": the message reactions property is documented as nullable from Discord, so according to the API this is a full and valid message. That being said, there should exist some functionality for bypassing the cache to fetch the message from the API. This is currently only possible if the message is actually partial (i.e. is missing documented non-null properties) and is likely an issue for other API objects.

I am very much against returning "complete" objects from either this endpoint or others; this opens a very large area for subtle bugs since we'd have to verify that every endpoint we hit returns whatever we consider to be a "complete" object. It also requires some magic from Discord.js to make it happen (i.e. extra API calls), which users might not be expecting.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smchase picture smchase  Â·  3Comments

PassTheMayo picture PassTheMayo  Â·  3Comments

Dmitry221060 picture Dmitry221060  Â·  3Comments

ghost picture ghost  Â·  3Comments

tom-barnes picture tom-barnes  Â·  3Comments