This is a simple question, and I'm surprised that I can't find a clear answer to it anywhere. I'm making an API and I need to define an Interface that can have multiple (string) properties, but there's no set number of properties and no set names for them (but they all have to have string values). So all of the following objects would match the type:
{ slot: "ten" }
{ class: "Luxury", base: "never", city: "Timbuktu" }
{ slot: "ten", class: "Luxury" }
I've thought of the following.
interface MyInterface {
[key: string]: string;
}
But to me, this says that the objects can have only one property (of varying name), rather than that they can have multiple properties (of varying names).
What's the best way to do this? Note that I can't control what property names the code that calls my API will use. Callers can use whatever property names that they want.