I'm facing an issue with getting my Angular 2 app to compile while using experimental JavaScript array features like the flat()
method.
To enable these features, I added the esnext.array
option in the tsconfig.json
file, so the lib
section now includes:
"lib": [
"es2017",
"esnext.array",
"dom"
],
Upon checking the lib.esnext.array.d.ts
file, I found that it indeed defines the flat()
method.
However, despite this configuration, I keep encountering a compilation error:
ERROR in src/app/services/service.ts(286,22): error TS2339: Property 'flat' does not exist on type 'ReadonlyMap[]'.
UPDATE 1:
I also tested using the esnext
option, but the error persisted.
Additionally, I confirmed that Angular CLI recognizes the lib
options by entering a non-existent one like esnext.array.dfgdfg
.
UPDATE 2: To rule out any issues with TypeScript version 2.9.2 or the Angular toolchain, I set up a simple project in plain TypeScript:
// greeter.ts
function greeter(persons: string[]) {
return "Hello, " + persons.flat().join();
}
var user: string[] = ["Jane User"];
document.body.innerHTML = greeter(user);
// tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"lib": [
"es2017",
"esnext.array",
"dom"
]
}
}
After trying to compile it with TypeScript versions 2.9.2, 3.0.1, and typescript@next
, I consistently receive the same error message:
greeter.ts:2:32 - error TS2339: Property 'flat' does not exist on type 'string[]'.
2 return "Hello, " + persons.flat().join(); ~~~~
I am puzzled about what could be causing this issue. Any insights would be greatly appreciated.