API endpoints that I call deliver data in the following shapes:
interface ArrayResponse<T> {
data: Partial<T>[]
}
interface ObjectResponse<T> {
data: Partial<T>
}
I've written a function that calls endpoints and returns responses:
function fetchOne<T>(path: string): ObjectResponse<T> {
// HTTP call
}
function fetchMany<T>(path: string): ArrayResponse<T> {
// Exact same HTTP logic as above
}
Ideally I want to have a single response type:
interface Response<T> {
data: Partial<T> | Partial<T>[]
}
But I what I really want is to be able to have the above type to determine Partial or Partial[] based on the value passed for T.
So Response<T> would result in data: Partial<T> and Response<T>[] results in data: Partial<T>[].
I'm also open to other creative ways of achieving the same effect.
![vscode detects this as a T[]](https://i.stack.imgur.com/hpF8n.png)
