Let's say I want to create an interface to describe this type of objects:
let myObj= {
"count": 3,
"key1": "foo",
"key2": "bar",
"key3": "baz"
};
Those object always have a property count of type number and the rest of the properties are strings
If I define my interface using index signatures like this:
interface MyObect {
count: number;
[key: string]: string;
}
I got the compiler error:
[ts] Property 'count' of type 'number' is not assignable to string index type 'string'.
So I have to define it like this:
interface MyObect {
count: number;
[key: string]: any;
}
But this definition is not as presise.
Is there a way to enforce the type of extra properties ?