当我瞄准es5时,如何将承诺与TypeScript结合使用?

当我瞄准es5时,如何将承诺与TypeScript结合使用?,typescript,ecmascript-6,promise,es5-compatiblity,Typescript,Ecmascript 6,Promise,Es5 Compatiblity,我不熟悉这个编译器lib选项是什么,如果我要更改它,它会有什么影响 我正试图瞄准较老的浏览器,我认为需要支持es5。我想这可以通过传输/聚合填充来实现?我的类型脚本配置是: TS2585: 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the `lib` compiler option to e

我不熟悉这个编译器
lib
选项是什么,如果我要更改它,它会有什么影响


我正试图瞄准较老的浏览器,我认为需要支持
es5
。我想这可以通过传输/聚合填充来实现?我的类型脚本配置是:

TS2585: 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

将以下内容添加到编译器选项中:

{
    "compilerOptions": {
        "sourceMap": true,
        "target": "es5",
        "declaration": true,
        "removeComments": false,
        "module" : "commonjs",
        "moduleResolution": "node",
        "resolveJsonModule": true,
    },
    "include": [
        "src/*"
    ],

    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}
lib
选项的描述更为详细

解释
target
lib
之间的差异


也就是说,如果您可以接受使用
es6
,那么我认为您可以将
target
设置为
“es6”
,而不是混用
lib

,您可能应该添加类似@types/es6 promise的内容
{
    "compilerOptions": {
        "sourceMap": true,
        "target": "es5",
        "declaration": true,
        "removeComments": false,
        "module" : "commonjs",
        "moduleResolution": "node",
        "resolveJsonModule": true,
    },
    "include": [
        "src/*"
    ],

    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}
"lib": [
        "dom",
        "es5",
        "es2015.promise"
    ]