Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript is wrongly inferring types and showing errors #5244

Open
Foxvyle-tec opened this issue Nov 27, 2024 · 0 comments
Open

Typescript is wrongly inferring types and showing errors #5244

Foxvyle-tec opened this issue Nov 27, 2024 · 0 comments
Labels
to triage Waiting to be triaged by a member of the team

Comments

@Foxvyle-tec
Copy link

Describe the bug

After defining types for the socket instance, the compiler is inferring the arguments wrongly in CLI lib

To Reproduce

Please fill the following code example:

Socket.IO server version: 4.8.1

Server

import { Server } from "socket.io";

const io = new Server(3000, {});

io.on("connection", (socket) => {
  console.log(`connect ${socket.id}`);

  socket.on("disconnect", () => {
    console.log(`disconnect ${socket.id}`);
  });
});

Socket.IO client version: 4.8.1

Client

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

interface CliToServ{
 frdRequest:(user:{userId:string}) =>void;
 } 

interface ServToCli{
 hello:() =>void; 
}

const socket:Socket<ServToCli, CliToServ>= io("ws://localhost:3000/", {}); 

socket.on("connect", () => {
  console.log(`connect ${socket.id}`);
});

socket.on("disconnect", () => {
  console.log("disconnect");
});

//this is where it falsely shows the err
try{
const res=await socket.emitWithAck("frdRequest", {userId:"1234"})
} catch{
//err handling here
} 

//it says I passed 2 arguments and it 
//expected 1
//To resolve this I had to pass a second
//unwanted prop to the interface ie

interface CliToServ{
 frdRequest:(user:{userId:string}, x:unknown) =>void;
 }

//with the above the err doesn't show /
//and still it doesn't infer that useless 
//prop

Expected behavior
With valid type definition it had not to make any warnings, and there was no need for me to add an unwanted prop

Platform:

  • Device: [Dell Latitude]
  • OS: [windows 10]

Additional context

That unwanted prop added it's also not inferred on emittion

@Foxvyle-tec Foxvyle-tec added the to triage Waiting to be triaged by a member of the team label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to triage Waiting to be triaged by a member of the team
Projects
None yet
Development

No branches or pull requests

1 participant