比如这个教程,
https://ts.xcatliu.com/advanced/class.htmlclass Animal {
constructor(name) {
this.name = name;
}
sayHi() {
return `My name is ${this.name}`;
}
}
let a = new Animal('Jack');
console.log(a.sayHi());
编译的时候报错如下:
ERROR in E:\dir\js\index.ts
./js/index.ts
[tsl] ERROR in E:\dir\js\index.ts(3,14)
TS2339: Property 'name' does not exist on type 'Animal'.
ERROR in E:\dir\js\index.ts
./js/index.ts
[tsl] ERROR in E:\dir\js\index.ts(6,35)
TS2339: Property 'name' does not exist on type 'Animal'.
debug方法是在constructor的上面一行加个name;(意思是先声明一下有此属性)
原来webpack 3系列的时候虽然记忆中好像也有这些报错,但都能正常编译输出,现在4系列不光报错,输出还为空,没输出任何文件。
想问一下该怎么办,不知道和tsconfig.json有没有关系,附上json文件
{
"compilerOptions":{
"removeComments":false,
"target":"ES5",
"lib":["ES2015","ES2015.Iterable","DOM"],
"sourceMap":true
},
"files":[
"./dir/index.ts"
]
}
--
FROM 49.210.130.*