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

Having trouble using the constructor w/ ClientOps #14

Closed
sjmcdowall opened this issue Aug 1, 2018 · 2 comments
Closed

Having trouble using the constructor w/ ClientOps #14

sjmcdowall opened this issue Aug 1, 2018 · 2 comments

Comments

@sjmcdowall
Copy link

sjmcdowall commented Aug 1, 2018

I am sure just is this a user error -- but I have some pretty simple TS code and it's throwing me a TS error. The code and error follow:

import { createHandyClient, IHandyRedis } from 'handy-redis';
import { BaseStore } from 'koa-session-ts';
import { ClientOpts } from '../../node_modules/@types/redis';

/**
 * RedisStore for koa-session
 *
 * @param {object} options the options pass to node_redis
 * @returns RedisStore instance
 */
export class RedisSessionStore extends BaseStore {
  // Class members
  readonly client: IHandyRedis;

  constructor(options?: ClientOpts) {
    super();

    this.client = createHandyClient(options);   // Error is here at options

It doesn't like the options I pass in ..following problem

I also tried to set the options to type ICreateHandyClient but effectively the same error..

I am using TS 2.9.2

[ts]
Argument of type 'ClientOpts | undefined' is not assignable to parameter of type 'RedisClient'.
  Type 'undefined' is not assignable to type 'RedisClient'.
(parameter) options: ClientOpts | undefined

It looks like it's taking only the last definition in the Interface or something .. ??

Again, I am probably just doing something wrong here ...

Thanks

@mmkal
Copy link
Owner

mmkal commented Aug 14, 2018

Hi - your code is working for me with this change:

import { createHandyClient, IHandyRedis } from 'handy-redis';
import { BaseStore } from 'koa-session-ts';
-import { ClientOpts } from '../../node_modules/@types/redis';
+import { ClientOpts } from 'redis';

The @types/redis package is actually a prod dependency for handy-redis (this might change in a future major version of this library though). If this still doesn't work for you, try npm uninstall @types/redis, and feel free to reopen this ticket if you have problems after that.

@mmkal mmkal closed this as completed Aug 14, 2018
@sjmcdowall
Copy link
Author

Thanks! Sort of a newbie bonehead move!!

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

No branches or pull requests

2 participants