I am trying to design an interface with a fixed key, as well as a variable key, like this :
interface Data {
api?: {
isReady: boolean;
};
[key: string]: string;
}
This setup gives me the following error message :
Property 'api' of type '{ isReady: boolean; }' is not assignable to string index type 'string'.
I understand that the statement [key:string]: string
specifies that "every key in this interface must have a string value", which contradicts the structure of api
. Therefore, the error is justified.
Is there a way to create an interface that combines a specific key/value pair along with a flexible key at the same level?
Thank you!