How to work with promisifyAll in typescript?

Consider the following code:

import redis = require('redis'); //Has ambient declaration from DT import bluebird = require('bluebird'); //Has ambient declaration from DT bluebird.promisifyAll((<any>redis).RedisClient.prototype); bluebird.promisifyAll((<any>redis).Multi.prototype); const client = redis.createClient(); client.getAsync('foo').then(function(res) { console.log(res); }); 

getAsync will fail because it is created on the fly and is not defined in any .d.ts file. So what is the right way to handle this?

Also, even though I have .d.ts files uploaded for redis, I still need to drop redis to any for promisifyAll . Otherwise, it will throw an error:

 Property 'RedisClient' does not exist on type 'typeof "redis"' 

Does he any just the easy way?

+7
javascript promise bluebird typescript
source share
1 answer

I solve this with a declaration combining the setAsync and getAsync . I have added the following code to my own .d.ts file.

 declare module "redis" { export interface RedisClient extends NodeJS.EventEmitter { setAsync(key:string, value:string): Promise<void>; getAsync(key:string): Promise<string>; } } 
+3
source share

All Articles