tsconfig.json 显然被忽略了?

mic*_*blu 4 javascript typescript

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

我有以下目录:

  • 测试.ts
  • tsconfig.json

测试.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')
Run Code Online (Sandbox Code Playgroud)

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6"
    },
    "files": [
        "./**/*.ts"
    ]
}
Run Code Online (Sandbox Code Playgroud)

当我跑步时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.
Run Code Online (Sandbox Code Playgroud)

Pen*_*gyy 5

当您运行tsc filename.ts编译指定文件时,tsconfig.json将被忽略。请参考这个问题

而不是tsc filename,你可以用tsc,这样总会搞定的tsconfig.json