I have this code in my TypeScript file:
class Template {
private templates = [
{
name: 'other',
template: `<h1>Template</h1>`
}
];
public getByName(name: string) {
return this.templates.find(t => t.name === name)
}
}
const t = new Template();
t.getByName('other');
When I try to compile it, I get this error:
error TS2550: Property 'find' does not exist on type '{ name: string; template: string; }[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.
However my lib compiler option is already set like this:
"compilerOptions": {
"target": "es2016",
"lib": ["es2016", "dom"],
...
}
I just need the array find
method in TypeScript, I don't know what else to do to get it.