[英]Add a property to the type of an Array typescript
Working on a chat app, I encountered a problem trying to add a property to the array of object.在使用聊天应用程序时,我在尝试将属性添加到 object 数组时遇到了问题。
// original array
const authors: User[] = []
//But I wanted to add something like this
const authors: User[] & { otherProperty: string }[] = []
I thing I could extend the array outside and then make it an array, but it is posible to do it with an intersection?我想我可以将数组扩展到外面,然后使它成为一个数组,但是可以用交叉点来做吗? I'm honestly curious
我真的很好奇
You want to add the property to User
right?您想将该属性添加到
User
权限吗?
const authors: (User & { otherProperty: string })[] = [];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.