Accessors are only available when targeting ECMAScript 5 and higher

前端 未结 14 1632
北荒
北荒 2020-12-23 13:07

I am trying to run this code but it is giving me following errors:

Animal.ts(10,13): error TS1056: Accessors are only available when targeting ECMAS

14条回答
  •  無奈伤痛
    2020-12-23 13:57

    I had the same problem trying to compile TypeScript code with Visual Studio Code. This solved the issue:

    1) tsconfig.json - add the target in the compilerOptions:

    {
        "compilerOptions": {
            "target": "es5",  // <-- here!
            "module": "commonjs",
            "sourceMap": true
        }
    }
    

    2) tasks.json - add the target argument:

    {
        "version": "2.0.0",
        "tasks": [
            {
                "taskName": "build",
                "type": "process",
                "command": "tsc",
                "args": [
                    "ts/Program.ts",
                    "--outDir", "js",
                    "--sourceMap",
                    "--watch",
                    "--target", "es5"  // <-- here!
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "presentation": {
                    "reveal": "always"
                },
                "problemMatcher": "$tsc"
            }
        ]
    }
    

提交回复
热议问题