首页 > 解决方案 > 类型“arrPostType”上不存在属性“find”

问题描述

定义数组对象及其查找方法时出现问题。
我的代码:

type postType = {
  id: string
  author: authorType
  text: string
  likesCount: number
}

type arrPostType = {
  userid: number
  posts: postType[]
}

const allPosts: arrPostType = [
  {
    userid: 2,
    posts: [
      {
        id: 1,
        author: {
          id: 2,
          name: 'Jordan'
        },
        text: 'Hello everybody',
        likesCount: 1
      }
    ]
  }
}

let posts = allPosts.find((p: arrPostType) =>
  p.userid === userid) // Property 'find' does not exist on type 'arrPostType'.  TS2339

在 es6 中设置目标没有帮助。

我不明白问题是什么。帮助

标签: typescripttypescript-typings

解决方案


推荐阅读