类型“ arrPostType”上不存在属性“ find”

时间:2020-07-06 16:30:32

标签: typescript typescript-typings

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

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中设置目标没有帮助。

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

0 个答案:

没有答案