23

I want to use getters and setters in Typescript. At the moment when I try this I get the following:

error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.

How do I configure my compiler in IntelliJ 14? Are there any disadvantages to this? DOes this produce a different type of Javascript that will only work on certain browsers?

Thanks

Roaders
  • 4,373
  • 8
  • 50
  • 71

4 Answers4

25

To change the compiler options you need to go to the FileWatcher Dialogue.

Settings -> Tools -> File Watchers

Select TypeScript and hit the edit (pencil) button.

Add

--target es5

to the arguments field

Roaders
  • 4,373
  • 8
  • 50
  • 71
  • 21
    Just in case you switch to Webstorm 10 and you are looking for the same thing you would have to go: Settings -> Language & Frameworks -> Typescript. And then inside "Command line options" insert `--target es5` – George Pligoropoulos Apr 16 '15 at 07:54
  • 2
    You'll also do the same thing as the comment from **George Pligor** about webstorm in IntelliJ 14.1 – rbnzdave May 14 '15 at 23:51
11

You can set the target version in your tsconfig.json:

"compilerOptions": {
    "target": "es5"
}

Here is a list of all the compiler options.

LisaMM
  • 675
  • 1
  • 16
  • 28
  • 5
    I think, this is the best solution. It allows to bundle the TypeScript configuration with the source files, independent from any IDE specific settings and/or project files. It also represents the configuration as a whole in a much clearer way. – Johannes Sep 07 '16 at 16:29
  • 2
    To use the tsconfig.json in your WebStorm project, go to File -> Settings... -> Languages & Frameworks -> TypeScript and switch from 'Set options manually' to 'Use tsconfig.json'. – Johannes Sep 07 '16 at 16:29
3

Setup the watcher to use the compiler flag --target es5.

Are there any disadvantages to this?

Properties (getter/setter) are not supported where es5 isn't supported (obsolete versions of browsers : see http://kangax.github.io/compat-table/es5/)

basarat
  • 261,912
  • 58
  • 460
  • 511
  • Thanks for that, I had seen that compiler flag already but have no idea where to set it. Thanks for the browser compatibility info. – Roaders Dec 27 '14 at 23:06
-2

I solved mine by compiling the file in command prompt using "tsc --target ES5 YourFile.ts"

Rapirap LeeYo
  • 55
  • 1
  • 9