Open
Description
Currently, we have this arrangement of types
react-use-websocket/src/lib/types.ts
Lines 62 to 69 in 0d9444d
The problem is, that we T
is not forwarded to the sendJsonMessage
member. If we try, we get an error: Type 'SendJsonMessage' is not generic.
, to fix that we can change
react-use-websocket/src/lib/types.ts
Line 52 in 0d9444d
from type SendJsonMessage = <T = unknown>(...)
to type SendJsonMessage<T = unknown> = (...)
(note the position of the =
sign).
So my first question is:
- Was this an oversight?
- Would
sendJsonMessage: SendJsonMessage<T>
a proper fix, or should we allow different types forsendJsonMessage
andlastJsonMessage
, e.g.:
export type WebSocketHook<Ret = unknown, Send = Ret, P = WebSocketEventMap['message'] | null> = {
sendMessage: SendMessage,
sendJsonMessage: SendJsonMessage<Send>,
lastMessage: P,
lastJsonMessage: Ret,
readyState: ReadyState,
getWebSocket: () => (WebSocketLike | null),
}
(also update useWebSocket
of course)
Here's a small playground I created to test this: Playground Link
Metadata
Metadata
Assignees
Labels
No labels