tsconfig.json显然被忽略了?

时间:2017-04-28 03:53:40

标签: javascript typescript

我需要帮助才能理解为什么我的tsconfig.json被忽略了? tsconfig.json的目标是es5,但我仍然收到此错误?

我有以下目录:

  • test.ts
  • tsconfig.json

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.

1 个答案:

答案 0 :(得分:2)

当您运行tsc filename.ts来编译指定的文件时,tsconfig.json将被忽略。 请参阅此issuse

您可以使用tsc filename代替tsc代替tsconfig.json

相关问题