Dramex 8ea7c7c7e4 fix(collection): preserve ReadonlyCollection through tap/each (#11501)
* fix(collection): preserve ReadonlyCollection through tap/each

`each` and `tap` return polymorphic `this`, which TypeScript resolves
against the `Omit<Collection, ...>` portion of `ReadonlyCollection`
rather than the full intersection. That let callers reach `set` and
`delete` on the result of a chain started from a `ReadonlyCollection`:

    const ro: ReadonlyCollection<string, number> = new Collection(...);
    ro.tap(() => {}).set('x', 0); // compiled, mutated the underlying Map

The fix omits `each` and `tap` from the base `Omit` and re-declares
them on the `ReadonlyCollection` side of the intersection so the return
type narrows back to `ReadonlyCollection`.

Closes #10514

* test(collection): gate readonly-chain checks behind if(false)

Previously the `@ts-expect-error` lines still executed the `set` and
`delete` mutations at runtime, and the final `size === 1` passed only
because they happened to cancel out. Wrapping the assertions in
`if (false)` keeps the compile-time guarantee while the backing
collection is truly untouched, and adds a `get('a') === 1` check as
a belt.

* test(collection): move readonly type checks to *.test-d.ts

Addresses review feedback. The type-level assertions around tap() and
each() preserving ReadonlyCollection belong in a *.test-d.ts file so
they run through vitest's typecheck pass instead of runtime.

Replaces the if(false)-gated @ts-expect-error block in collection.test.ts
with expectTypeOf assertions in a new collection.test-d.ts. Covers both
the no-thisArg and with-thisArg overloads of tap and each.
2026-04-20 19:15:29 +00:00
2025-10-31 11:15:45 +00:00
2023-05-03 02:14:22 +02:00
2023-08-22 09:40:11 +02:00
2023-08-22 01:33:47 +02:00
2022-07-19 20:11:23 +02:00
2025-07-13 19:39:47 +00:00


discord.js


Discord server npm version npm downloads Tests status Last commit. contributors backers Code coverage

Vercel Cloudflare Workers

About

This repository contains multiple packages with separate releases. You can find the assembled Discord API wrapper at discord.js. It is a powerful Node.js module that allows you to easily interact with the Discord API.

Packages

  • discord.js (source) - A powerful Node.js module for interacting with the Discord API
  • create-discord-bot (source) - A CLI tool to quickly scaffold a Discord bot project
  • @discordjs/brokers (source) - A collection of brokers for use with discord.js
  • @discordjs/builders (source) - A utility package for easily building Discord API payloads
  • @discordjs/collection (source) - A powerful utility data structure
  • @discordjs/core (source) - A thinly abstracted wrapper around the core components of the Discord API
  • @discordjs/formatters (source) - A collection of functions for formatting strings
  • @discordjs/proxy (source) - A wrapper around @discordjs/rest for running an HTTP proxy
  • @discordjs/rest (source) - A module for interacting with the Discord REST API
  • @discordjs/structures (source) - A wrapper around Discord's structures
  • @discordjs/util (source) - A collection of utility functions
  • @discordjs/voice (source) - A module for interacting with the Discord Voice API
  • @discordjs/ws (source) - A wrapper around Discord's gateway

Containers

  • discordjs/proxy (source) - A lightweight HTTP proxy for Discord's API

Extensions

Contributing

Please read through our contribution guidelines before starting a pull request. We welcome contributions of all kinds, not just code! If you're stuck for ideas, look for the good first issue label on issues in the repository. If you have any questions about the project, feel free to ask them on Discord. Before creating your own issue or pull request, always check to see if one already exists! Don't rush contributions, take your time and ensure you're doing it correctly.

Help

If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please join our Discord server.

Languages
TypeScript 61.1%
JavaScript 28.5%
MDX 10.1%
CSS 0.2%