socketio / socket.io-redis-streams-adapter

The Socket.IO adapter based on Redis Streams, allowing to broadcast events between several Socket.IO servers.
https://socket.io/docs/v4/redis-streams-adapter/
MIT License
30 stars 15 forks source link

0.2.0: Adapter type is no longer compatible with socker.io #14

Closed peterjuras closed 9 months ago

peterjuras commented 9 months ago

Hi,

after updating to 0.2.0, I'm getting the following TypeScript error message:

No overload matches this call.
  Overload 1 of 3, '(srv?: number | TServerInstance | undefined, opts?: Partial<ServerOptions> | undefined): Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any>', gave the following error.
    Type '(nsp: any) => RedisStreamsAdapter' is not assignable to type 'AdapterConstructor | undefined'.
      Type '(nsp: any) => RedisStreamsAdapter' is not assignable to type '(nsp: Namespace<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any>) => Adapter'.
        Type 'RedisStreamsAdapter' is missing the following properties from type 'Adapter': nsp, rooms, sids, encoder, and 34 more.
  Overload 2 of 3, '(srv: number | TServerInstance | Partial<ServerOptions> | undefined, opts?: Partial<ServerOptions> | undefined): Server<...>', gave the following error.
    Type '(nsp: any) => RedisStreamsAdapter' is not assignable to type 'AdapterConstructor | undefined'.

from the following code:

import type { Server } from "http";

import { createAdapter } from "@socket.io/redis-streams-adapter";
import { createClient } from "redis";
import { Server as SocketIOServer } from "socket.io";

export async function createRealtimeServer(server: Server) {
  const redisClient = createClient();
  const io = new SocketIOServer(server, {
    adapter: createAdapter(redisClient),
  });

  return io;
}

Error screenshot:

image

Dependency versions:

Can you please check & fix this issue?

darrachequesne commented 9 months ago

Hi! I wasn't able to reproduce. Could you please check the version of socket.io-adapter, which is installed by the socket.io and @socket.io/redis-streams-adapter packages? You may have two distinct versions, which could explain the typescript error.

master-bogdan commented 9 months ago

+1 I had same error

Dependency versions:

UPDATE I was deleted everything from package.json and package-lock.json by hands and reinstall again these packages, and it's stop give me a TypeScript error

peterjuras commented 9 months ago

Thanks for the quick replies. I re-ran npm install after adjusting the lockfile a bit and it is also working for me now 👍