typescript - 类型“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 中设置目标没有帮助。
我不明白问题是什么。帮助
解决方案
推荐阅读
- expression - 根据 Julia 中的列表表达式制作表达式列表
- scala - spark read 在 Scala UDF 函数中不起作用
- python - 如何将 Jupyter notebook 捕获的 TensorBoard 生成的绘图下载为 PDF?
- android - 无法使用 volley 在 android 中发送发布请求(BasicNetwork.performRequest:API 的意外响应代码 404)
- c - C:对 LibConfuse 内部函数的未定义引用
- python-2.7 - 将列转换为列表
- c - C 编程:在给定真值向量和预测的情况下找到混淆矩阵
- authentication - 大使的 API 密钥身份验证
- javascript - 为什么 clearInterval 在我的脚本中不起作用?
- javascript - Tensorflow:替代 DenseFeatures 输入层以移植到 tfjs