I need to define a recursive interface with an optional property that has a dynamic key:
export interface IAnswerValueSet {
[linkId: string]: {
answerValueSet?: fhir4.ValueSet;
answerValueSetUrl: string;
[linkId: string]?: IAnswerValueSet; // problem is here
};
}
I'm getting two errors from the compiler:
Property or signature expected from `?:`
Member 'IAnswerValueSet' implicitly has an 'any' type.
If I use a known key for the nested IAnswerValueSet
it works as expected, but I need the key to be dynamic.
How can I define this interface correctly?