后续属性声明必须具有相同的类型

时间:2018-04-27 01:30:22

标签: typescript webpack vue.js

我有两个webpack配置文件

webpack1.config.js

const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');

const config = {
    entry: [
        './app/App1/App1.ts'
    ],

    output: {
        path: path.resolve('', 'web/assets/js'),
        filename: 'app1.js'
    },

    resolve: {
        extensions: [".ts", ".tsx", ".vue", ".js"],
        modules: [
            path.resolve('./app'),
            path.resolve('./node_modules')
        ],
        alias: {
            'vue$': 'vue/dist/vue.esm.js'
        },
    },

    module: {
        rules: [
            {
                test: /\.ts?$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
                options: {
                    appendTsSuffixTo: [/\.vue$/]
                }
            },
            {
                test: /\.vue?$/,
                loader: 'vue-loader',
                exclude: /node_modules/,
                options: {
                    esModule: true
                }
            }
        ]
    },
};

module.exports = config;

webpack2.config.js

const path = require('path');

const config = {
    entry: [
        './app/App2/App2.ts'
    ],

    output: {
        path: path.resolve('', 'web/assets/js'),
        filename: 'app2.js'
    },

    resolve: {
        extensions: [".ts", ".tsx", ".vue", ".js"],
        modules: [
            path.resolve('./app'),
            path.resolve('./node_modules')
        ],
        alias: {
            'vue$': 'vue/dist/vue.esm.js'
        },
    },

    module: {
        rules: [
            {
                test: /\.ts?$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
                options: {
                    appendTsSuffixTo: [/\.vue$/]
                }
            },
            {
                test: /\.vue?$/,
                loader: 'vue-loader',
                exclude: /node_modules/,
                options: {
                    esModule: true
                }
            }
        ]
    },
};

module.exports = config;

现在,当我使用app1编译webpack1.config.js时,它会抛出错误后续属性声明必须具有相同的类型。物业'用户'必须是“IUser'”类型,但这里有类型' IUser'

因为在App1.ts我有以下行

   import IUser from 'IUser'; // /app/App1/IUser.ts
   ...
   user:IUser;
   ...

App2.ts

   import IUser from 'IUser'; // /app/App2/IUser.ts
   ...
   user:IUser;
   ...

问题是,地理位置app/App2还包含IUser界面,但如何在webpack1.config.js中告诉停止查看app/App2个地点?

我已经尝试了类似

的内容

``

           test: /\.ts?$/,
            loader: 'ts-loader',
            exclude: [/node_modules/, /app\/App2/], // so maybe try to omit App2?
            options: {
                appendTsSuffixTo: [/\.vue$/]
            }

所以我试图排除app/App2,但它没有帮助,我仍然看到错误。 我有最新版本的TypeScript,很有趣,因为它一直很好用,今天突然出现了这个错误(我没有更新任何东西,只是像我平时那样尝试编译项目)。

0 个答案:

没有答案