Reputation: 890
In Typescript, I have created a TiketsItem
and the interface with that TiketsItem
array. How can I get the type from arr
which must have history
key?
interface TicketsItem {
id: number
status: string
addedAt: string
subject: string
history?: {
date: string
message: string
messageBy: string
}[]
}
export interface Tickets extends Array<TicketsItem> { }
const arr: Tickets = [
{
"id": 1,
"subject": "Email certificate expired",
"status": "Client response pending",
"addedAt": "2020-09-23",
"history": [
{
"date": "20-10-10",
"message": "sjflsjl",
"messageBy": "client"
},
]
},
{
"id": 2,
"subject": "Issue with Email certificate",
"status": "Client response pending",
"addedAt": "2020-09-23"
},
]
const ticketOne = arr[0]
I'm trying to use
const ticketOne = arr[0]
type TicketsItemMustHaveHistory = typeof ticketOne
but it returns TicketsItem again.
Upvotes: 0
Views: 106