-
Notifications
You must be signed in to change notification settings - Fork 12.8k
How to let TypeScript work with bluebird promisifyAll or promisify? #8685
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
Comments
Or should I use RxJS instead of bluebird? |
You would need to do: import * as Promise from 'bluebird';
import * as redis from 'redis';
const redisAsync: any = Promise.promisifyAll(redis); There won't be any intellisense, but it will let you call .xxxAsync(). |
@JoshGlazebrook Thanks! Some Javascript magic trick still need dynamic. |
How about: import * as Promise from 'bluebird';
import * as Redis from 'redis';
declare module 'redis' {
export interface RedisClient extends NodeJS.EventEmitter {
hdelAsync(...args: any[]): Promise<any>;
// add other methods here
}
}
const oldRedisClient = Redis.createClient(...);
const redisClient = Promise.promisifyAll(oldRedisClient) as Redis.RedisClient; // cast
// redisClient.hdelAsync now shows up in intelliSense. |
How about import * as Bluebird from 'bluebird';
import * as AWS from 'aws-sdk';
export interface IPromisifedS3 extends AWS.S3 {
[x: string]: any
}
const s3 = new AWS.S3();
Bluebird.promisifyAll(s3);
export default s3 as IPromisifedS3; This enables type checking and auto completion for the normal functions while allowing to use the promosified methods |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Uh oh!
There was an error while loading. Please reload this page.
This code will not work with TypeScript, since it has not enough type information for the promisified redis.
The text was updated successfully, but these errors were encountered: