Skip to content

Able to modify ReadonlyCollection #10514

Open
Open
@TmGL

Description

@TmGL

Which package is this bug report for?

collection

Issue description

I doubt this matters too much, but here it is anyway.

Steps to reproduce:

  1. Call any method which has the this return type upon the Collection.
  2. The method will return a Collection which is no longer of the ReadonlyCollection type...
  3. ...thus, you can call methods such as .set() and .delete() on the Collection.

Code sample

const testColl: ReadonlyCollection<string, number> = new Collection<string, number>([
    ['id', 123]
]);

testColl.tap(() => {}).set('unexpected', 0);
testColl.each(() => {}).delete('id');

console.log(testColl); // Collection(1) [Map] { 'unexpected' => 0 }

Versions

  • @discordjs/collection 2.1.1
  • discord.js 14.16.2
  • typescript 5.3.3
  • NodeJS 20.14.0
  • Windows 22H2

Issue priority

Low (slightly annoying)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions