我需要帮助才能理解为什么我的tsconfig.json被忽略了? tsconfig.json的目标是es5
,但我仍然收到此错误?
我有以下目录:
test.ts
let passcode = "roscoes"
class Employee {
private _fullName: String
get fullName(): String {
return this._fullName
}
set fullName(newName: String) {
if (passcode && passcode === "roscoes") {
this._fullName = newName
} else {
console.log("Error: Not authorized ")
}
}
}
let employee = new Employee()
employee.fullName = "Johnny Appleseed"
if (employee.fullName) {
console.log(employee.fullName)
}
console.log('testing')
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6"
},
"files": [
"./**/*.ts"
]
}
当我运行tsc test.ts
时,我得到:
test.ts(6,6): error TS1056: Accessors are only available when targeting ECMAScript 5 and
higher.
test.ts(10,6): error TS1056: Accessors are only available when targeting ECMAScript 5 an
d higher.
答案 0 :(得分:2)
当您运行tsc filename.ts
来编译指定的文件时,tsconfig.json
将被忽略。
请参阅此issuse。
您可以使用tsc filename
代替tsc
代替tsconfig.json
。