socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

TypeScript type breakage under pnpm / preserveSymlinks=true due to extending Emitter from another package

Open anthonyalayo opened this issue 1 month ago • 2 comments

Is your feature request related to a problem? Please describe.

When using socket.io-client in a symlinked setup (such as pnpm + preserveSymlinks=true or local linking via npm link), TypeScript loses several instance methods (on, emit, etc.) on the Socket class.

This happens because Socket extends the Emitter class from the @socket.io/component-emitter package:

import { Emitter } from "@socket.io/component-emitter";

export class Socket extends Emitter { ... }

Under preserveSymlinks=true, there can be multiple physical copies of @socket.io/component-emitter, resulting in distinct module identities for TypeScript. As a result, Socket no longer appears to implement the correct emitter API.

This affects:

  • pnpm users (the default node_modules structure is symlink-based)
  • anyone linking socket.io-client locally (e.g. pnpm link, npm link, or monorepo setups)

Describe the solution you'd like

One of the following would make the types robust against symlinked environments:

  • Re-export the emitter types from socket.io-client to unify identity.
  • Use composition instead of inheritance for emitter behavior.
  • Define an internal interface for the emitter API instead of importing the external class.

Example of a minimal re-export solution:

// socket.io-client/index.ts
import { Emitter } from "@socket.io/component-emitter";
export { Emitter }; // re-export canonical symbol

export class Socket extends Emitter { ... }

anthonyalayo avatar Nov 03 '25 05:11 anthonyalayo