Quite a simple question, but I haven't found an answer yet anywhere: Is there some switch to make TypeScript pile arrow functions into plain JavaScript functions?
I use them a lot in my code, and I don't want to rewrite everything. But I lately realized, that IE doesn't support them.
I already tried to switch the script version to ES5, but then my code won't pile anymore, because I'm using "filter" as well, which doesn't seem to be a part of it. However, I don't know, if that would do the job in the first place.
Quite a simple question, but I haven't found an answer yet anywhere: Is there some switch to make TypeScript pile arrow functions into plain JavaScript functions?
I use them a lot in my code, and I don't want to rewrite everything. But I lately realized, that IE doesn't support them.
I already tried to switch the script version to ES5, but then my code won't pile anymore, because I'm using "filter" as well, which doesn't seem to be a part of it. However, I don't know, if that would do the job in the first place.
Share Improve this question asked Sep 29, 2017 at 8:32 André R.André R. 4377 silver badges17 bronze badges2 Answers
Reset to default 5If you want to just convert your arrow functions to regular functions and keep the rest of the code piling, you can set the target
config to es5
and lib
property to es6
:
"pilerOptions": {
"target": "es5",
"lib": ["es6"],
// ....
}
This will allow your code that uses ES6 features to pile while targeting ES5. But you have to make sure those features (like filter
) are available at runtime. If they are not available it will throw runtime exceptions.
Arrow functions are a part of ES6, but you should be able to transpile your code to ES5 with Babel. There is a babel-preset-typescript which you should be able to use for this.