打字稿不定式界面推断自身
我正在寻找一种从此API响应中制作类型/接口的方法,嵌套注释
属性对我来说是具有挑战性的。
"data": [
{
"id": 1,
"comment": "This is the comment to another comment",
"approved": true,
"archived": 0,
"pinned": 0,
"reported": 0,
"created_at": "2022-06-24T06:12:25.000000Z",
"updated_at": "2022-06-24T06:12:25.000000Z",
"comments": [
{
"id": 2,
"comment": "This is the comment to another comment",
"approved": true,
"archived": 0,
"pinned": 0,
"reported": 0,
"created_at": "2022-06-24T06:12:37.000000Z",
"updated_at": "2022-06-24T06:12:37.000000Z",
"comments": [
{
"id": 3,
"comment": "This is the comment to another comment",
"approved": true,
"archived": 0,
"pinned": 0,
"reported": 0,
"created_at": "2022-06-24T06:32:52.000000Z",
"updated_at": "2022-06-24T06:32:52.000000Z",
"comments": [],
"commented": {
"id": 1,
"first_name": "Test",
"last_name": "Testi",
"full_name": "Test Testi"
}
},
{
"id": 4,
"comment": "This is the comment to another comment",
"approved": true,
"archived": 0,
"pinned": 0,
"reported": 0,
"created_at": "2022-06-24T06:32:57.000000Z",
"updated_at": "2022-06-24T06:32:57.000000Z",
"comments": [],
"commented": {
"id": 1,
"first_name": "Test",
"last_name": "Testi",
"full_name": "Test Testi"
}
}
],
"commented": {
"id": 1,
"first_name": "Test",
"last_name": "Testi",
"full_name": "Test Testi"
}
}
],
"commented": {
"id": 1,
"first_name": "Test",
"last_name": "Testi",
"full_name": "Test Testi"
}
},
],
I'm looking for a way to make a type/interface from this API response, The nested comments
property is challenging for me.
"data": [
{
"id": 1,
"comment": "This is the comment to another comment",
"approved": true,
"archived": 0,
"pinned": 0,
"reported": 0,
"created_at": "2022-06-24T06:12:25.000000Z",
"updated_at": "2022-06-24T06:12:25.000000Z",
"comments": [
{
"id": 2,
"comment": "This is the comment to another comment",
"approved": true,
"archived": 0,
"pinned": 0,
"reported": 0,
"created_at": "2022-06-24T06:12:37.000000Z",
"updated_at": "2022-06-24T06:12:37.000000Z",
"comments": [
{
"id": 3,
"comment": "This is the comment to another comment",
"approved": true,
"archived": 0,
"pinned": 0,
"reported": 0,
"created_at": "2022-06-24T06:32:52.000000Z",
"updated_at": "2022-06-24T06:32:52.000000Z",
"comments": [],
"commented": {
"id": 1,
"first_name": "Test",
"last_name": "Testi",
"full_name": "Test Testi"
}
},
{
"id": 4,
"comment": "This is the comment to another comment",
"approved": true,
"archived": 0,
"pinned": 0,
"reported": 0,
"created_at": "2022-06-24T06:32:57.000000Z",
"updated_at": "2022-06-24T06:32:57.000000Z",
"comments": [],
"commented": {
"id": 1,
"first_name": "Test",
"last_name": "Testi",
"full_name": "Test Testi"
}
}
],
"commented": {
"id": 1,
"first_name": "Test",
"last_name": "Testi",
"full_name": "Test Testi"
}
}
],
"commented": {
"id": 1,
"first_name": "Test",
"last_name": "Testi",
"full_name": "Test Testi"
}
},
],
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Typescript Playground Link
Comment
is part oflib.dom .d.ts
,所以更好地使用commentdata
而不是Typescript Playground Link
Comment
is part oflib.dom.d.ts
, so better useCommentData
instead