Typescript for onConnect connectionParams? #310
Answered
by
enisdenjo
theogravity
asked this question in
Q&A
-
What's the generic to use for defining the
|
Beta Was this translation helpful? Give feedback.
Answered by
enisdenjo
Feb 19, 2022
Replies: 1 comment 1 reply
-
There was none at the time of asking. The idea was that the server has to deal with clients that may not comply with the required However, you indeed expect most of the clients to send over the proper params, so why not have a generic! Landed in v5.6.0 (through #311). Your example becomes: useServer<{ token: string }>(
{
onConnect: async (ctx) => {
// connectionParams can be undefined because you shouldnt
// rely on all clients on the internet to send them
const token: string | undefined = ctx.connectionParams?.token;
},
},
...
); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
theogravity
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There was none at the time of asking. The idea was that the server has to deal with clients that may not comply with the required
connectionParams
too, so I left the generic out.However, you indeed expect most of the clients to send over the proper params, so why not have a generic! Landed in v5.6.0 (through #311). Your example becomes: