Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@anthonyalayo

Description

@anthonyalayo

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 { ... }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions