Accessors are only available when targeting ECMAScript 5 and higher

前端 未结 14 1629
北荒
北荒 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:41

    If you're dealing with single file you could do this

    tsc your-file.ts --target ES2016 --watch

    If you wants inside your tsconfig.json for entire project configuration

    { "compilerOptions": { "target": "ES2016" } "files": [] }

    You may want to use either ECMAScript numeric "es6", "es7", "es8" or year of release like "ES2015", "ES2016", "ES2017".

    ESNext targets latest supported ES proposed features.

    0 讨论(0)
  • 2020-12-23 13:42

    The only thing which worked for me was to specify the Target on macOS and Windows. Please note the parameter -t is standing for Target.

    tsc -t es5 script.ts
    

    You can run the command on your terminal.

    0 讨论(0)
  • 2020-12-23 13:48

    try setting up a tsconfig.json file in your project:

    {
      "compilerOptions": {
      "target": "es5"
      }
      "files": []
    }
    

    that will tell the typescript compiler to target a version specifically.

    0 讨论(0)
  • 2020-12-23 13:48

    Finally worked out for me. Run the file then state the target flag

    tsc script.ts --t es5 enter link description here

    0 讨论(0)
  • 2020-12-23 13:49

    I was having the same problem. What I read from the docs is that the tsconfig.json file is ignored if you specify the files.

    My tsconfig.json file

    {
      "compilerOptions": {
        "target": "es5"
      },
      "include": [
        "*.ts"
      ]
    }
    

    And I run it from command line

    tsc && node *.js
    
    0 讨论(0)
  • 2020-12-23 13:50

    Using Visual Stido 2017 ?
    1- Solution Explorer>Right Click To Project
    2- Add>New Item
    3- (Search section >type this> typescript)
    4- Select "TypeScript Json Configuration File"

    thats it
    at the end of this steps, tsconfig.json will be added to project with default set applied to ES5

    you don't have to change anything. just recompile your project and error gonna out.

    0 讨论(0)
提交回复
热议问题