A StackBlitz example that I have set up is failing to compile due to the usage of flatMap. The error message reads:
Property 'flatMap' does not exist on type 'string[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
I attempted changing the lib
to 'es2019'
after consulting this post about flatMap, flat, flatten doesn't exist on type any[], but unfortunately, it did not resolve the issue.
Exploring other solutions from related queries, I also experimented with 'esnext'
. However, this approach proved ineffective as well.
The excerpt from my tsconfig file looks like this:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
...
"lib": ["es2019"]
},
...
}
This is a portion of the code where flatMap is invoked:
import { Component, VERSION } from '@angular/core';
import { get } from 'lodash';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
...
ngOnInit() {
const testData = [...];
testData['columns'] = ['name', 'count', 'successes'];
const countCategoryArr: Array<string> = get(testData, 'columns', []).slice(1);
const moveCounts = countCategoryArr.flatMap((entry) =>
hist.map((d) => ({
move: d.name,
countCategory: entry,
count: d[entry],
}))
);
}
}
The error displayed on StackBlitz can be viewed https://i.sstatic.net/bcMFj.jpg