I need to define an interface that reflects this part of a response:
"responses": {
"accepted": [],
"declined": [],
"messages": {
"id1": {
"profile": "",
"message": "Lorem ipsum"
},
"id2": {
"profile": "",
"message": "Lorem ipsum"
}
}
So far I have defined the responses like this:
export interface Response {
accepted: string[],
declined: string[],
messages: Messages
}
How do I define the Messages interface properly?
export interface Messages {
profile: string,
message: string,
}
>Solution :
You forgot to add string keys to messages, and rename Messages to Message to reflect that this is one object:
export interface Response {
accepted: string[],
declined: string[],
messages: Record<string, Message>
}
export interface Message {
profile: string,
message: string,
}