定义数组对象及其查找方法时出现问题。
我的代码:
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中设置目标没有帮助。
我不明白问题是什么。帮助