Home > Mobile >  Add a property to the type of an Array typescript
Add a property to the type of an Array typescript

Time:01-19

Working on a chat app, I encountered a problem trying to add a property to the array of 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

CodePudding user response:

You want to add the property to User right?

const authors: (User & { otherProperty: string })[] = [];
  •  Tags:  
  • Related