I'm having an issue with declaring an interface where a property is an array of an {}.
This is the interface I defined
export interface GlobalEventRegistration {
'sourceName': string,
'listenFor': [
{
'sourceName': string,
'eventName': string
}
]
}
My code to implement.
const registration: GlobalEventRegistration = {
sourceName: this._className,
listenFor: [
{
sourceName: 'MapComponent',
eventName: 'test'
},
{
sourceName: 'SomeComponent',
eventName: ''
}
]
}
The error from the IDE
TS2322: Type '[{ sourceName: string; eventName: string; }, { sourceName: string; eventName: string; }]' is not assignable to type '[{ sourceName: string; eventName: string; }]'. Source has 2 element(s) but target allows only 1. GlobalEventRegistration.ts(16, 3): The expected type comes from property 'listenFor' which is declared here on type 'GlobalEventRegistration'
I'm not clear on why or how to get it to allow me to have the array of inner {} for the 'listenFor'.
Thanks for looking.