I was playing around with TypeScript a bit and found a little oddity. Let's say I am building a little application that (sadly) needs to support IE8, too. So I set the TypeScript-compiler to target ES3.
I assumed I could safely use ECMAScript 5.1 goodies such as Array.prototype.reduce
in my .ts file and that TypeScript will take care of including some kind of polyfill for that. This does not seem to be the case, though:
function joinStuff (stuff : string[], joiner : string = ' ') {
return stuff.reduce((previous, current) =>
previous ? previous + joiner + current : current
) || '';
}
will get compiled into:
function joinStuff(stuff, joiner) {
if (joiner === void 0) { joiner = ' '; }
return stuff.reduce(function (previous, current) {
return previous ? previous + joiner + current : current;
}) || '';
}
Now this is not ECMAScript 3 compatible code! (and it won't run in IE8, of course). What am I missing?