Skip to content

Typescript for onConnect connectionParams? #310

Answered by enisdenjo
theogravity asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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;
    },
  },
  ...
);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@theogravity
Comment options

Answer selected by theogravity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants