mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-11-27 14:55:20 +03:00
Fixes Websocket Typescript issues (#1277)
This commit is contained in:
parent
84766299cb
commit
67f88cc50e
@ -28,9 +28,13 @@ export function useSocketListener<Event extends keyof ServerToClientEvents>(
|
|||||||
// Casting to `keyof ServerToClientEvents` is necessary because TypeScript
|
// Casting to `keyof ServerToClientEvents` is necessary because TypeScript
|
||||||
// reports the handler function as incompatible with the event type.
|
// reports the handler function as incompatible with the event type.
|
||||||
// See https://github.com/wasp-lang/wasp/pull/1203#discussion_r1232068898
|
// See https://github.com/wasp-lang/wasp/pull/1203#discussion_r1232068898
|
||||||
socket.on(event as keyof ServerToClientEvents, handler)
|
|
||||||
|
// We are wrapping it in `Extract<...>` due to Typescript infering string | number
|
||||||
|
// in the case of default events being used.
|
||||||
|
type AllowedEvents = Extract<keyof ServerToClientEvents, string>;
|
||||||
|
socket.on(event as AllowedEvents, handler)
|
||||||
return () => {
|
return () => {
|
||||||
socket.off(event as keyof ServerToClientEvents, handler)
|
socket.off(event as AllowedEvents, handler)
|
||||||
}
|
}
|
||||||
}, [event, handler])
|
}, [event, handler])
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ export async function init(server: http.Server): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await {= userWebSocketFn.importIdentifier =}(io, context)
|
await ({= userWebSocketFn.importIdentifier =} as any)(io, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
{=# isAuthEnabled =}
|
{=# isAuthEnabled =}
|
||||||
|
Loading…
Reference in New Issue
Block a user