fastify / fastify-redis

Plugin to share a common Redis connection across Fastify.
MIT License
198 stars 31 forks source link

TypeScript error when using Redis.Cluster from ioredis #162

Closed jimmy-guzman closed 1 year ago

jimmy-guzman commented 1 year ago

Prerequisites

Fastify version

4.3.0

Plugin version

6.0.0

Node.js version

16.14.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.5

Description

Let's say we're using an existing Redis.Cluster client we get the following TypeScript error

    Type 'Redis | Cluster' is not assignable to type 'Redis'.
      Type 'Cluster' is not assignable to type 'Redis'.

Steps to Reproduce

import fastifyRedis from "@fastify/redis";
import fastify from "fastify";
import Redis from "ioredis";

const instance = fastify();

const client = new Redis.Cluster([{ host: REDIS_HOST, port: REDIS_PORT }], {
  redisOptions: { password: REDIS_PASSWORD },
});

instance.register(fastifyRedis, {
  client,
  closeClient: true,
});

Expected Behavior

I believe changing this signature to client: Redis | Cluster would fix this issue.

Uzlopak commented 1 year ago

PR is welcome. Dont forget to add a typings test.