I need to describe an interface where:
- A property with a 'billingAddress' key has a value of an Object with specific properties, and
- Properties with any other key have a value of a string.
I tried this:
interface DoesNotWork {
[key: string]: string;
billingAddress?: {
foo: string;
}
}
Typescript complains that Property 'billingAddress' of type '{ foo: string; } | undefined' is not assignable to 'string' index type
Fair enough: when DoesNotWork.billingAddress is defined, Typescript won't know whether it should be assigned a string, an object or undefined.
How do I describe the interface in a way that Typescript will understand?