Skip to content

fix(socket.io-client): export reserved-events types to fix ts(4023) on declaration emit - #5533

Closed
SnowingFox wants to merge 1 commit into
socketio:mainfrom
SnowingFox:fix/5307-export-reserved-events
Closed

SnowingFox wants to merge 1 commit into
socketio:mainfrom
SnowingFox:fix/5307-export-reserved-events

Conversation

@SnowingFox

Copy link
Copy Markdown
Contributor

Description

Fixes #5307.

When a downstream consumer re-exports a value whose (inferred) type references socket.io-client's Socket / Manager types, TypeScript's declaration emitter must be able to name the "reserved events" maps those classes are parameterized with. Those maps were not exported, so any tsc --declaration pass over such a consumer failed with:

Exported variable 'X' has or is using name 'SocketReservedEvents' from external module "..." but cannot be named.ts(4023)

As diagnosed in the issue discussion, the failing names (SocketReservedEvents, ManagerReservedEvents, HandshakeData, WriteOptions, TransportReservedEvents, Cookie) are all unexported interfaces.

Changes

Type-only additions (no runtime behaviour change):

  • packages/socket.io-client/lib/socket.ts: export SocketReservedEvents
  • packages/socket.io-client/lib/manager.ts: export ManagerReservedEvents
  • packages/engine.io-client/lib/socket.ts: export SocketReservedEvents, HandshakeData, WriteOptions
  • packages/engine.io-client/lib/transport.ts: export TransportReservedEvents
  • packages/engine.io-client/lib/globals.node.ts: export Cookie (referenced by the exported parse/CookieJar)
  • re-export the new types from both packages' lib/index.ts, following the pattern used for DisconnectDescription in Export DisconnectDescription type directly from 'socket.io-client' #5392

Test

Added a declaration-emit regression fixture at packages/socket.io-client/test/types/ts4023.test.ts that mirrors the issue's reproducer (an exported value whose inferred type references the reserved-events maps of Socket, Manager, the Engine.IO Socket and its Transport). On main it fails with the exact ts(4023) errors reported in the issue:

./node_modules/.bin/tsc -p packages/socket.io-client/test/types/tsconfig.json

After the fix, the same command exits cleanly (verified with the TypeScript version pinned in this repo, ^6.0.3).

Related

darrachequesne pushed a commit that referenced this pull request Sep 11, 2026
Export reserved event and related option interfaces from the client packages so
that declaration emit can name inferred public types.

This fixes TS4023 errors when consumers export values derived from typed emitter
methods, such as `socket.io.listeners`.

Related: #5307
darrachequesne pushed a commit that referenced this pull request Sep 11, 2026
Export reserved event and related option interfaces from the client packages so
that declaration emit can name inferred public types.

This fixes TS4023 errors when consumers export values derived from typed emitter
methods, such as `socket.io.listeners`.

Related: #5307
@darrachequesne

Copy link
Copy Markdown
Member

Awesome, thanks 👍

Rebased and split by packages:

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TS: Exported variable X has or is using name Y from external module Z but cannot be named.ts(4023)

2 participants