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

Offen
#5,411 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
typescript

Rechercherichtung

Beginne mit dem Beispiel in socket.io-client/index.ts und der Socket-Deklaration, und verfolge dann, wie @socket.io/component-emitter unter preserveSymlinks=true importiert wird. Reproduziere das Problem in einem pnpm-, npm-link- oder Monorepo-Setup und vergleiche die vorgeschlagenen Ansätze zur Typidentität. Als erledigt gilt die Aufgabe, wenn Socket seine on- und emit-Typen beim Symlinking beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

needs investigation

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 { ... }
Vorherrschende Sprache
TypeScript
Sterne
63.2k
Forks
10.2k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
4

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus socketio/socket.io

Alle Issues in socketio/socket.io

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.