Typescript 后续属性声明必须具有相同的类型
我有两个Typescript 后续属性声明必须具有相同的类型,typescript,webpack,vue.js,Typescript,Webpack,Vue.js,我有两个webpackconfig文件 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('', 'w
webpack
config文件
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;
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;
webpack2.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;
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;
现在,当我使用webpack1.config.js
编译app1
时,它抛出一个错误后续属性声明必须具有相同的类型。属性“user”的类型必须为“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
位置
我已经试过了
``
因此,我试图排除app/App2
,但没有效果,我仍然看到了错误。
我有最新版本的TypeScript,很有趣,因为它一直运行良好,今天突然出现了这个错误(我没有更新任何内容,只是像往常一样尝试编译项目)。也许排除应用程序应该是一个字符串?因此,
“/app/App2”
否则它是一个正则表达式,可能只匹配名为app/App2
的即时文件夹,而不是实际路径谢谢您的评论。我也试过了,可惜没有用。嗯,那么可能path.resolve(uu dirname,“/App2”)