我有函数返回字符串Q.Promise
module test {
export function promiseString (): Q.Promise<string> {
var deferred = Q.defer<string>();
deferred.resolve('someMessage');
return deferred.promise;
}
}
如何将返回值用作字符串?
选项#1:
Q.fcall(promiseString).then(function (message: string) {
// compilation error about incompatible parameters
});
选项#2:
Q.fcall(promiseString).then(function (promise: Q.Promise<string>) {
console.log(typeof promise); // output string
// but i can't use promise as string further
});
答案 0 :(得分:4)
如果函数总是返回一个promise(延迟或其他),那么你不必用Q.fcall
来调用它。只需致电:
promiseString().then(...)