My request response needs to be defined, but the key name may vary. It will always be a string, but the specific key depends on the request.
These are the possible responses:
{ someRequest: { message: 'success', status: 200 } }
{ someOtherRequest: { message: 'unauthorized', status: 401 } }
Considering that the someRequest
key may change while the other remains constant, I attempted this:
export interface Response<T extends string> {
[key: T]: { message: string; status: number; }
}
However, it resulted in an error - "An index signature parameter type must be either 'string' or 'number'". How can I define a generic key string?