请问老师,interface 是关键字,如何解决

来源:3-4 由浅入深 webpack - 编译 typescript

Benjamin_Smith

2018-03-13

ERROR in ./src/app.ts
Module parse failed: The keyword 'interface' is reserved (3:0)
You may need an appropriate loader to handle this file type.
| const NUM = 45
|
| interface Cat {
|   name: String,
|   gender: String
npm install webpack@3.10.0 typescript ts-loader awesome-typescript-loader --save-dev
const NUM = 45

interface Cat {
name: String,
gender: String
}

function touchCat(cat: Cat) {
console.log('miao~', cat.name);
}

touchCat({
name: 'tom',
gender: 'male'
})

webpack.config.js 和 tsconfig.js 配置跟你视频里的一样

写回答

4回答

tulies

2018-03-28

你贴的代码 test: /\.tex?$/。。 这也不对啊  tsx

0
0

tulies

2018-03-28

如果你webpack用的是3.x的版本,把你的ts-loader也降级到3.x的版本就可以了。 不要用最新的。

0
0

Benjamin_Smith

提问者

2018-03-15

module.exports = {
entry: {
'app': './src/app.ts'
},

output: {
filename: '[name].bundle.js'
},

module: {
rules: [{
test: /\.tex?$/,
use: {
loader: 'ts-loader'
}
}]
}
}

我仔细看了好多遍,跟视频里的是一样的啊

0
0

qbaty

2018-03-14

loader 好像没有配置对,tsx?

0
1
Benjamin_Smith
module.exports = { entry: { 'app': './src/app.ts' }, output: { filename: '[name].bundle.js' }, module: { rules: [{ test: /\.tex?$/, use: { loader: 'ts-loader' } }] } }
2018-03-15
共1条回复

四大维度解锁Webpack3.0前端工程化

前端开发标配,灵活掌握Webpack3.0的使用可以极大的提高前端开发的效率

1188 学习 · 403 问题

查看课程