One of my functions has a general structure:
export function limitToApiContraints<T extends Array>(payload: T, type: IQueueTypes) {
...
}
However, there is an issue with the generic signature that prompts the following error message:
The generic type 'Array' needs 1 type argument.
To address this, if I modify it to:
export function limitToApiContraints<T extends Array<any>>(payload: T, type: IQueueTypes) {
return foo as T;
}
the function's signature successfully passes structural testing. But after returning foo
as T, it evaluates to ready: any[] | IGitHubRepoMap[]
(where T = IGitHubRepoMap[]).
How can I specify that T will always be an array while ensuring a distinct type is returned?