Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are typings available? #661

Open
quinnlangille opened this issue Jan 14, 2019 · 20 comments
Open

Are typings available? #661

quinnlangille opened this issue Jan 14, 2019 · 20 comments

Comments

@quinnlangille
Copy link

I'm trying to use this package in a typescript application but can't find type declarations anywhere. Just making sure they don't exist before I create some.

@stipsan
Copy link
Owner

stipsan commented Jan 15, 2019

Last I checked there wasn't any, but I noticed that there's a @types/ioredis already.

Even though my long term goal for this library is to move all of it to TypeScript I would love to see a PR with definitions. That way TS users can benefit from it in the meantime. And when work starts on moving the source to TS the library definitions will be a great starting point 😄

@quinnlangille
Copy link
Author

Yeah I can make the PR no problem, will work on it this week. I'll make it to definitelyTyped for now, just for ease of install. Once the library moves to TS we can migrate here

@stipsan
Copy link
Owner

stipsan commented Jan 16, 2019

Ok cool 👍

@skyzenr
Copy link

skyzenr commented Mar 8, 2019

Hi @quinnlangille, @stipsan Any ETA on this?

@datdevboi
Copy link

Any update on this?

@quinnlangille
Copy link
Author

Negative, I haven't had time I expected to work on it - however there is an increasing need in office for a solution, so I may get it done soon. If anyone is needed typings now and want them done fast, feel free to take on the task! Just ping here to keep everyone informed

@steveklebanoff
Copy link

Here's a workaround that I'm using in the mean time. It assumes you have ioredis and @types/ioredis installed in addition to iosredis-mock.

import * as IORedis from 'ioredis';

const MockIORedis = require('ioredis');
const mockRedisClient = new MockIORedis() as IORedis.Redis;

@stipsan stipsan pinned this issue May 13, 2019
@notaphplover
Copy link

@stipsan I just saw your comment, I'm working on a PR with definitions but I'd like to ensure some assumptions I've made:

  1. ioredis-mock have the commands listed here and are equivalent with its ioredis commands.
  2. Since multi() and exec() are supported, pipelining is supported and work exactly equal than ioredis pipelining with the commands that ioredis-mock supports.

Once I finish the definitions, I have two options:

  1. Submit a PR to the DefinitelyTyped repo. I'd love to show you the definition file before doing that.
  2. Submit a PR to this repo and put the definitions under a "types" folder. This approach is not my favourite one, its used in the knex repo but I do prefer to have type definitions in the DefinitelyTyped repo because is a the standard way, its transparent to JS users and does not require to change the typeRoots option of the TS project.

¿Are my assumptions right? ¿How should I provide you the definitions?

@notaphplover
Copy link

@stipsan I submitted the PR #849 in order to show you the type definitions. If everything is OK we can merge the definitions or submit a PR to the DefinitelyTyped repo.

@CarsonMcKinstry
Copy link

@notaphplover any news on the PR in the DefinitelyTyped repo?

@notaphplover
Copy link

@CarsonMcKinstry wow I really forgot that, sorry. I've been a bit busy but I think I'll have enough time this weekend.

@robcresswell
Copy link

@notaphplover Let us know if you need a hand, I'm also interested in this 😄

@arctouch-gabrielluchtenberg

@notaphplover any updates on this? I couldn't find the PR on the DefinitelyTyped repository. :'(

@chanced
Copy link

chanced commented Jul 11, 2020

@steveklebanoff aren't you basically just creating an instance of IORedis rather than IORedis-Mock? I'm not sure what I'm missing there?

import RedisMock from 'ioredis-mock';
import { Redis as IORedis } from 'ioredis';
const Redis = RedisMock as IORedis;

Doesn't work

Conversion of type '(...args: any[]) => any' to type 'Redis' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.

Type '(...args: any[]) => any' is missing the following properties from type 'Redis': Promise, status, connect, disconnect, and 200 more.ts(2352)

import RedisMock from 'ioredis-mock';
import * as IORedis from 'ioredis';
const Redis = RedisMock as IORedis;

Doesn't work because

Cannot use namespace 'IORedis' as a type.

Same goes for

import RedisMock from 'ioredis-mock';
import * as IORedis from 'ioredis';
import * as IORedisMock from 'ioredis-mock';

const TempIORedis = IORedisMock as unknown;
const Redis = TempIORedis as IORedis;

@havsar
Copy link

havsar commented Nov 25, 2020

@chanced

This seems to work for me as a workaround:

import * as IORedis from 'ioredis'

const IoRedisMock: typeof IORedis = require('ioredis-mock')

@robcresswell
Copy link

@arctouch-gabrielluchtenberg @havsar You can use the IORedis types, but the mock doesn't fully cover it / has some differences, which are documented, so your types will be wrong and lead to some hard to identify issues.

@Theo-Evrard
Copy link

@notaphplover Do you have any news for this? Cheers.

@notaphplover
Copy link

@Theo-Evrard I'm so sorry, the definition file is in this PR, feel free to do the PR to DefinitelyTyped. It's been a while and some definitions probably needs an update, but I would hazard to say it's better than having no types. I've been wondering if maybe types should be included in this repo:

  1. npm @types/foo versions probably won't match npm foo versions.
  2. It's easier to submit an issue in this way. If you have an issue with the @types/foo library you need to know who are the contributors to the library and mention them.

I know it's the opposite I said previously, but now I think it's the best way.

I'm sorry for half and a year of silence, I have no excuses at all (even if it's true I've been busy)

@crispinkoech
Copy link

crispinkoech commented Sep 30, 2021

Hey, so there's the data property available on the redis-mock options but it isn't available on ioredis types 🙂

@trim21
Copy link

trim21 commented Dec 9, 2022

updates: it's available on npm now, you can just use @types/ioredis-mock


I create a PR at DefinitelyTyped but it's not merged yet. DefinitelyTyped/DefinitelyTyped#63499

You can add this snippet to your project

ioredis-mock.d.ts

declare module 'ioredis-mock' {
  import ioredis = require('ioredis');

  type RedisOptions = { data?: Record<string, unknown> } & ioredis.RedisOptions;

  interface Constructor {
    new (port: number, host: string, options: RedisOptions): ioredis.Redis;
    new (path: string, options: RedisOptions): ioredis.Redis;
    new (port: number, options: RedisOptions): ioredis.Redis;
    new (port: number, host: string): ioredis.Redis;
    new (options: RedisOptions): ioredis.Redis;
    new (port: number): ioredis.Redis;
    new (path: string): ioredis.Redis;
    new (): ioredis.Redis;
  }

  const redisMock: Constructor;
  export default redisMock;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests