[英]Typescript compile error in promise.then
I'm trying to use promises in typescript. 我正在尝试在打字稿中使用Promise。 I used tsd to install es6-promise and added the reference to my file. 我使用tsd安装es6-promise,并将引用添加到我的文件中。 It understands promises for the most part, but I'm having difficulty chaining them with then
. 它在大多数情况下都了解诺言,但是我很难将它们与then
。
function foo() : Promise<any> {
var p: Promise<any> = Promise.resolve();
var x: Promise<any> = Promise.resolve();
p = p.then(x);
return p;
}
gives me this at the location of p.then(x)
: 给我这个在p.then(x)
的位置:
error TS2345: Argument of type 'Promise' is not assignable to parameter of type '(value: any) => {} | 错误TS2345:类型'Promise'的参数不能分配给类型'(value:any)=> {} | Thenable<{}>'. thenable <{}>'。
Is this somehow a bug in the type definition , or am I using it wrong? 这是类型定义中的错误,还是我使用的错误?
p.then(x); p.then(x);
This is invalid. 这是无效的。 x
needs to be function. x
需要起作用。 Here you have it as a promise. 在这里,您可以兑现承诺。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.