相关疑难解决方法(0)

如何打开承诺的类型

说我有以下代码:

async promiseOne() {
  return 1
} // => Promise<number>

const promisedOne = promiseOne()

typeof promisedOne // => Promised<number>
Run Code Online (Sandbox Code Playgroud)

我将如何提取承诺结果的类型(在这个简化的情况下是一个数字),因为它是自己的类型?

typescript

24
推荐指数
5
解决办法
3136
查看次数

去抖动和返回

我对这段代码有疑问:

function aFunction(){
  ....
    var deferred = $q.defer();
    debounce(function () {
       deferred.resolve(service.subscribe0(data));
    }, 350);
  return deferred.promise;
}
Run Code Online (Sandbox Code Playgroud)

返回的承诺永远不会得到解决。Debounce 功能是第 3 方功能,从 NPM 进行了大量下载,因此我可以确定它可以工作。

难道是因为 return 语句“删除”了函数的作用域?我怎样才能避免这种情况并兑现承诺?

javascript scope promise debouncing

0
推荐指数
1
解决办法
3083
查看次数

标签 统计

debouncing ×1

javascript ×1

promise ×1

scope ×1

typescript ×1