简体   繁体   English

如何强制Webpack 3抛出TypeScript错误?

[英]How to force Webpack 3 to throw TypeScript errors?

// index.ts

let a = 1;
a.map();

Webpack doesn't throw this TS error about method "map" on type "number. Do you know how check these errors automatically during webpack build? Webpack不会在类型“ number”上引发有关方法“ map”的此TS错误。 您知道如何在Webpack构建期间自动检查这些错误吗?

Can't find anything on the internet. 在互联网上找不到任何内容。

Previously I saw this: https://cloud.githubusercontent.com/assets/376414/7276837/840b4dec-e8da-11e4-8362-c44f531d8cd9.png 以前我看到了这个: https : //cloud.githubusercontent.com/assets/376414/7276837/840b4dec-e8da-11e4-8362-c44f531d8cd9.png

How can I get the same output of webpack (TS errors) using webpack 3? 如何使用webpack 3获得相同的webpack输出(TS错误)?

TypeScript thinks it's ok (any valid JS is also valid TypeScript), so, any project could be bundled with any JS error. TypeScript认为还可以(任何有效的JS也是有效的TypeScript),因此,任何项目都可以与任何JS错误捆绑在一起。

If I'm running tsc app/index.ts then I see the error: app/index.ts(8,3): error TS2339: Property 'map' does not exist on type 'number'. 如果我正在运行tsc app / index.ts,那么我会看到错误:app / index.ts(8,3):错误TS2339:类型“ number”上不存在属性“ map”。

So, TypeScript compiler throws the error, but webpack (ts-loader I think) ignores it. 因此,TypeScript编译器会引发错误,但webpack(我认为是ts-loader)会忽略该错误。

I'm using webpack 3.8.1 我正在使用webpack 3.8.1

Here is config: 这是配置:

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
        })
    ]

};

do you ever heard about linting ? 您听说过棉绒吗? here 's the loader for tslint for webpack 是tslint的webpack加载程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM