You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create two methods in my react client to use with socket.io. One for emitting events and one for listening. The goal is to export these two functions from a file where I'm setting up my socket logic so I don't actually have to expose the socket object itself. Here's the code I have currently:
The emit function is fine and I've been using it in my components but the listen function, which seems like it should work on the same basis, gives a TS error on the socket.on(event, listener); line. The listener argument has a few TS errors but they're all generally this format:
Type '((s: string) => void) | ((n: number) => void)' is not assignable to type 'FallbackToUntypedListener<EventName extends "connect" | "connect_error" | "disconnect" ? SocketReservedEvents[EventName] : EventName extends "eventA" | "eventB" ? ServerToClientEvents[EventName] : never>'.
Does anyone know what causes the TS compiler to give this error?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to create two methods in my react client to use with socket.io. One for emitting events and one for listening. The goal is to export these two functions from a file where I'm setting up my socket logic so I don't actually have to expose the socket object itself. Here's the code I have currently:
https://codesandbox.io/s/heuristic-currying-ylwp66?file=/src/index.ts
The emit function is fine and I've been using it in my components but the listen function, which seems like it should work on the same basis, gives a TS error on the
socket.on(event, listener);
line. Thelistener
argument has a few TS errors but they're all generally this format:Does anyone know what causes the TS compiler to give this error?
Beta Was this translation helpful? Give feedback.
All reactions