// index.ts

let a = 1;
a.map();


Webpack不会在类型“ number”上引发有关方法“ map”的此TS错误。
您知道在Webpack构建期间如何自动检查这些错误吗?

在互联网上找不到任何东西。

以前我看过这个:https://cloud.githubusercontent.com/assets/376414/7276837/840b4dec-e8da-11e4-8362-c44f531d8cd9.png

如何使用webpack 3获得相同的webpack输出(TS错误)?

TypeScript认为还可以(任何有效的JS也是有效的TypeScript),因此,任何项目都可以与任何JS错误捆绑在一起。

如果我正在运行tsc app / index.ts,那么我会看到错误:
app / index.ts(8,3):错误TS2339:类型“ number”上不存在属性“ map”。

因此,TypeScript编译器会引发错误,但webpack(我认为是ts-loader)会忽略该错误。

我正在使用webpack 3.8.1

这是配置:

let path = require('path'),
    webpack = require('webpack'),
    HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {

    entry: path.resolve('app/index.ts'),

    output: {
        path: path.resolve('dist'),
        filename: 'app.js'
    },

    resolve: {
        extensions: ['.js', '.vue', '.json', '.ts'],
        alias: {
            vue: path.resolve('node_modules/vue/dist/vue.js'),
            app: path.resolve('app')
        }
    },

    module:{
        rules: [
            { test: /\.tsx$/, use: 'ts-loader' },
            { test: /\.vue$/, use: 'vue-loader' },
            { test: /\.pug$/, use: 'pug-loader' }
        ]
    },

    plugins: [
        new HtmlWebpackPlugin({
            template: path.resolve('app/index.pug'),
            cache: false
        }),
        new webpack.LoaderOptionsPlugin({
            debug: true
        })
    ]

};

最佳答案

您听说过linting吗? here是tslint Webpack的加载器

关于javascript - 如何强制Webpack 3抛出TypeScript错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47152532/

10-12 07:39
查看更多