【发布时间】:2016-08-02 11:08:21
【问题描述】:
考虑以下代码:
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 会出错,因为它是动态创建的,没有在任何.d.ts 文件中定义。那么处理这个问题的正确方法是什么?
此外,即使我为 redis 加载了 .d.ts 文件,我仍然需要将 redis 转换为 any 以用于 promisifyAll。否则会溢出错误:
Property 'RedisClient' does not exist on type 'typeof "redis"'
将其输入any 是唯一简单的方法吗?
【问题讨论】:
-
你有没有找到解决这个问题的方法?我遇到了同样的问题...
-
@zam6ak 是的,通过使用声明合并。请参阅下面的答案。
标签: javascript typescript promise bluebird