danitseitlin / redis-modules-sdk-ts

A Software development kit for easier connection and execution of Redis Modules commands.
Apache License 2.0
185 stars 29 forks source link

remove `@types/ioredis` from package.json #220

Closed JustGreg closed 1 year ago

JustGreg commented 1 year ago

I think there is no need for @types/ioredis ioredis contains build in typescript declerations @types/ioredis is used with version 4.28.10 ioredis is used with version 5.2.3

This cause an error on my project when i want to do something like this:

import type Redis from 'ioredis';
import { Redisearch } from 'redis-modules-sdk';

class RedisAdapter {
  public client!: Redis;
  public search!: Redisearch;

  public async init() {
    this.search = new Redisearch({
      ...
    });
    await this.search.connect();
    this.client = this.search.redis; // type error
  }
}

export const redis = new RedisAdapter();
danitseitlin commented 1 year ago

@JustGreg Hi, will look into it asap. if that's the case, we will remove it. thanks for the issue 🔥

danitseitlin commented 1 year ago

@JustGreg Can you share the error you have please?

JustGreg commented 1 year ago

@danitseitlin thank you for the fast response! here is the type error:

src/adapters/redis.ts(18,5): error TS2322: Type 'import("/builds/projectname/node_modules/redis-modules-sdk/node_modules/ioredis/built/Redis").default' is not assignable to type 'import("/builds/projectname/node_modules/ioredis/built/Redis").default'.
  Types of property 'options' are incompatible.
    Type 'import("/builds/projectname/node_modules/redis-modules-sdk/node_modules/ioredis/built/redis/RedisOptions").RedisOptions' is not assignable to type 'import("/builds/projectname/node_modules/ioredis/built/redis/RedisOptions").RedisOptions'.
      Type 'RedisOptions' is not assignable to type 'CommonRedisOptions'.
        Types of property 'Connector' are incompatible.
          Type 'import("/builds/projectname/node_modules/redis-modules-sdk/node_modules/ioredis/built/connectors/ConnectorConstructor").default | undefined' is not assignable to type 'import("/builds/projectname/node_modules/ioredis/built/connectors/ConnectorConstructor").default | undefined'.
            Type 'import("/builds/projectname/node_modules/redis-modules-sdk/node_modules/ioredis/built/connectors/ConnectorConstructor").default' is not assignable to type 'import("/builds/projectname/node_modules/ioredis/built/connectors/ConnectorConstructor").default'.
              Type 'import("/builds/projectname/node_modules/redis-modules-sdk/node_modules/ioredis/built/connectors/AbstractConnector").default' is not assignable to type 'import("/builds/projectname/node_modules/ioredis/built/connectors/AbstractConnector").default'.
                Property 'connecting' is protected but type 'AbstractConnector' is not a class derived from 'AbstractConnector'.

I added @types/ioredis (v. 4.28.10) to my project and the error disappeared. Now i removed @types/ioredis again and the error didn't show up again. ¯_(ツ)_/¯

danitseitlin commented 1 year ago

So I took the code you shared and started testing and I couldn't reproduce the issue. I am using dependencies: { "ioredis": "5.2.3", "redis-modules-sdk": "1.3.4", "typescript": "4.2.3" }

I ran tsc on the file and it doesn't seem to throw the error you are talking about. Can you share what version of TS + redis-modules-sdk you're using?

JustGreg commented 1 year ago

I'm sorry, i can't reproduce this issue either. I think you can close this issue?

danitseitlin commented 1 year ago

@JustGreg All good! happy we looked into it anyways :) If you have any questions, feel free to open issues and discussions. Happy weekend ✌🏼