I would like to do something like this
interface Foo {
firstException: number;
secondException: string[];
[key: string]: string; // doesn't do what I want
}
But the last line causes type errors
Property 'firstException' of type 'number' is not assignable to 'string' index type 'string'.
I have to do [key: string]: any;
or [key: string]: unknown;
. I could also do [key: string]: string | number | string[];
but then I'll have to check the type any time I access a property.
Is there a way to say that all keys that are not explicitly defined will hold string values?