socketio / socketio/socket.io

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

Open
#5,307 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation
Dominant language
TypeScript
Stars
63.2k
Forks
10.3k
Avg merge
11d 20h
Merged PRs (30d)
2

Description

Describe the bug
There are many type errors shown within the editor (VS code) that result from the use of the ‘socket’ type.
Building the application does not throw any TypeErrors.

I use the client in a Pinia store in Vue.
As soon as the Socket type is used within the store definition, the editor shows an error.
When using the variable connection via imports, this error extends to the entire files where the variable is used.

Is this due to the use with Pinia or Vue or the defined types in the socket-io client?

Image

To Reproduce

Socket.IO client version: ^4.8.1

"vue": "^3.4.29",
"vue-router": "^4.3.3"
"pinia": "^2.3.0",
"vite": "^5.3.1",

"@tsconfig/node20": "^20.1.4",
"@types/eslint": "~9.6.0",
"@types/node": "^20.14.5",

Client

import { defineStore } from "pinia";
import { io, type Socket } from "socket.io-client";

export const useConnectionStore = defineStore("connection", {
  state: () => {
    return {
      connection: undefined as undefined | Socket,
    };
  },
  getters: {
    connectionStatus: (state) => !!state.connection,
  },
  actions: {
    connectClient(): void {
      if (this.connectionStatus) return;
      this.connection?.disconnect();
      this.connection = io("<server url>", {
        reconnection: true,
        reconnectionDelayMax: 10000,
        auth: (cb) => {
          cb({ token: localStorage.getItem("accessToken") });
        },
      });

      this.connection.on("connect", () => {
        console.log("success");
      });
      this.connection.on("connect_error", (err) => {
        console.log(err);
      });
      this.connection.on("disconnecting", () => {
        this.connection?.disconnect();
      });
      this.connection.on("disconnect", () => {
        this.$reset();
      });
      this.connection.on("error", (msg: string) => {
        console.log(msg);
      });
    },
    disconnectClient(): void {
      this.connection?.disconnect();
    },
  },
});


Expected behavior
No type errors should be displayed in the editor.

Platform:

  • OS: Win10

Additional context
Shown Type Errors:

Exported variable 'useConnectionStore' has or is using name 'Cookie' from external module "<path>/node_modules/engine.io-client/build/esm/globals.node" but cannot be named.ts(4023)
Exported variable 'useConnectionStore' has or is using name 'HandshakeData' from external module "<path>/node_modules/engine.io-client/build/esm/socket" but cannot be named.ts(4023)
Exported variable 'useConnectionStore' has or is using name 'ManagerReservedEvents' from external module "<path>/node_modules/socket.io-client/build/esm/manager" but cannot be named.ts(4023)
Exported variable 'useConnectionStore' has or is using name 'SocketReservedEvents' from external module "<path>/node_modules/engine.io-client/build/esm/socket" but cannot be named.ts(4023)
Exported variable 'useConnectionStore' has or is using name 'SocketReservedEvents' from external module "<path>/node_modules/socket.io-client/build/esm/socket" but cannot be named.ts(4023)
Exported variable 'useConnectionStore' has or is using name 'TransportReservedEvents' from external module "<path>/node_modules/engine.io-client/build/esm/transport" but cannot be named.ts(4023)
Exported variable 'useConnectionStore' has or is using name 'WriteOptions' from external module "<path>/node_modules/engine.io-client/build/esm/socket" but cannot be named.ts(4023)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied Pinia store example with the listed TypeScript, Vite, and Socket.IO client versions, then inspect how the exported store type exposes the imported Socket type and its external declarations. Done means the editor no longer reports the listed TS4023 errors for the store and its consumers.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.