IE11 中的打字稿和承诺

Pre*_*ton 2 fetch promise typescript internet-explorer-11

我正在使用 Webpack 编译 Typescript (v2.4.2)。一切都编译正常,但是当我在 IE11 中运行我的代码时,我收到以下错误:'Promise' 未定义。

这是我的 tsconfig:

{
    "compilerOptions": {
        "outDir": "./wwwroot/js",
        "sourceMap": true,
        "allowJs": true,
        "lib": [
            "dom",
            "es5",
            "scripthost",
            "es2015.iterable"
        ],
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "skipDefaultLibCheck": true,
        "types": [ "es6-promise" ]
    },
    "include": [
        "./Ts/**/*"
    ]
}
Run Code Online (Sandbox Code Playgroud)

这是我的 webpack 配置:

const path = require('path');
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
    entry: {
        main: "./Ts/main.ts"
    },
    output: {
        filename: "[name].js",
        path: path.resolve(__dirname, "wwwroot/js")
    },
    devtool: "source-map",
    resolve: {
        extensions: [".ts", ".js"]
    },
    module: {
        rules: [
            { test: /\.ts?$/, loader: "awesome-typescript-loader" },
            { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
        ]
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            name: 'vendor',
            minChunks: Infinity
        })
    ]
};
Run Code Online (Sandbox Code Playgroud)

我知道我需要某种 polyfill,但我不确定是什么或如何实现它。到目前为止,我所看到的一切都暗示了某些 polyfill,例如 Promise 和 Whatwg-Fetch,但是每当我添加它们时,都会出现编译错误。

Dan*_*rom 5

IE 11 本身不支持 Promise,这与 Typescript 无关(Typescript 库实际上并未向代码添加任何内容)

您可以使用bluebird作为 Promise 库

npm install --save bluebird

还安装类型: npm install --save-dev @types/bluebird

import * as Promise from "bluebird"