相关疑难解决方法(0)

TypeScript Promise TS2304 TS2529

我有以下代码:

function asyncFunc1(): Promise<string> {
    return new Promise<string>(x => x);
}
Run Code Online (Sandbox Code Playgroud)

这产生了以下错误:

TS2304:找不到名字'承诺'

所以我把它改为明确声明'Promise':

///<reference path="../typings/modules/bluebird/index.d.ts" />

import * as Promise from 'bluebird';

function asyncFunc1(): Promise<string> {
    return new Promise<string>(x => x);
}
Run Code Online (Sandbox Code Playgroud)

现在我收到以下错误:

TS2529:重复标识符'Promise'.编译器在包含异步函数的模块的顶级范围内保留名称"Promise"

我怎样才能解决这个悖论?

javascript promise typescript

6
推荐指数
1
解决办法
4689
查看次数

标签 统计

javascript ×1

promise ×1

typescript ×1