admin管理员组文章数量:1332389
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.
本文标签: TypeScript unable to use find methodStack Overflow
版权声明:本文标题:TypeScript unable to use find method - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742291972a2447973.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论