简体   繁体   English

类型 Posts[] 上不存在属性查找

[英]property find does not exists on type Posts[]

I created the following interface:我创建了以下界面:

export interface Post {
    _id: string;
    admin: Admin;
    comments: PostComment[];
    createdAt: Date;
    modified: boolean;
    text?: string;
    desc?: string;
    photoPath?: string;
}

But when I used this:但是当我使用这个时:

const post = posts.find((e: Post) => e._id === cmnt.postId);

it throws error, 'Property 'find' does not exist on type 'Post[]'.. How to fix this...它抛出错误,'属性'find'在类型'Post []'上不存在..如何解决这个问题......

You need to set your compiler target to ES6 in tsconfig.您需要在 tsconfig 中将编译器target设置为 ES6。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打字稿“属性在类型元素上不存在” - Typescript “Property does not exists on type Element” 存在时类型上不存在属性 - Property does not exist on type when it exists 打字稿:请求类型上不存在“已解码”属性 - Typescript: Property 'decoded' does not exists on type Request mysql2 模块中的类型 ... OkPacket 上不存在属性“长度” - Property 'length' does not exists on type ... OkPacket in mysql2 module &#39;Readonly&lt;{}&gt; &amp; Readonly&lt;{ children?: ReactNode; 类型上不存在属性“导航” }&gt; - Property 'navigation' does not exists on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }> 在 Typescript 中解构赋值和“选择”时,类型上不存在属性 - Property does not exists on type when destructuring assignment and 'Pick' in Typescript 错误 TS:“元素”类型上不存在属性“数据集” - error TS: Property 'dataset' does not exists on type 'Element' React JS中类型&#39;Readonly &lt;{}&gt;&#39;上不存在属性&#39;currentTime&#39; - Property 'currentTime' does not exists on type 'Readonly<{}>' in react js 类型“ITravel”上不存在属性“长度”。 TS2339 - Property 'length' does not exists on type 'ITravel'. TS2339 Javascript,如果存在,则查找嵌套属性 - Javascript, find nested property if exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM