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

Readonly arrays in interfaces don't allow dynamically adding data #10339

Open
ImRodry opened this issue Jun 8, 2024 · 0 comments
Open

Readonly arrays in interfaces don't allow dynamically adding data #10339

ImRodry opened this issue Jun 8, 2024 · 0 comments

Comments

@ImRodry
Copy link
Contributor

ImRodry commented Jun 8, 2024

Which package is this bug report for?

discord.js

Issue description

The change in #10045 made it so that if you have a variable typed as one of the interfaces affected by the PR (will use BaseMessageOptions as an example) you will not be able to perform operations like push to your components, embeds, files and stickers arrays, even if you declare those arrays yourself and know they're not readonly. The goal of this change was to allow both readonly and mutable arrays to be passed, which does happen but only if you pass an array directly to the property, after that it is treated as readonly regardless. This was also discussed in https://discord.com/channels/222078108977594368/1249001503742758984
I don't think we're gaining anything from this change and would like to propose reverting the change on interfaces (while keeping it on methods)

Code sample

const res: InteractionReplyOptions = {}
res.embeds = []
res.embeds.push(new EmbedBuilder({description: "Test" })) //This errors because you cannot .push on a readonly array
// This is a simplified code sample

Versions

14.15.3

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

Not applicable

Which gateway intents are you subscribing to?

Not applicable

I have tested this issue on a development release

No response

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

No branches or pull requests

1 participant