Using typescript@3.6 and given this tsconfig.json
{
"compilerOptions": {
"target": "ES2018",
"lib": [
"ES2019",
"DOM"
],
"module": "commonjs",
"pretty": true,
"outDir": "dist",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"src/**/*.ts",
"tests/**/*.ts",
"cli.ts"
]
}
I assumed that I could make use of the new es2019 features while still generating valid es2018 code. So I thought I could use Array.prototype.flat
and Array.prototype.flatMap
.
Yet when compiling and running my code I get the error:
TypeError: anArray.map(...).flat is not a function
I am using node@10 for now and it does not natively support these functions, node@11 would but I don't want to upgrade node yet.
I was expecting to make use of future features through typescript. Yet when I look in the compiled js-file, I see the native construct being used -- so I am not wondering why it fails. I was expecting a polyfill there. I am wondering how to get es2019 features while still targeting older versions of ecma-script.
Am I enabling it wrong? What am I missing?
(This question is not about finding alternatives for the prototype functions. I am used of using lodash, that would be my fallback.)