#How to handle generic types does not satisfy X
19 messages · Page 1 of 1 (latest)
MultiSearchResponse can only take elements that are DocumentSchema[]
but the function you wrote accepts anything as T
and uses that same T, and passes it to MultiSearchResponse
you need to put the same constraint on the function as well
thanks for your reply, so do I need an intermediary time such as:
type TypesenseEmployeeDocument<T extends DocumentSchema> = T?
private async performMultiSearch<T extends DocumentSchema[]>(
// ...
): Promise<MultiSearchResponse<T>> {
}
oh, wait
forget what I just said
that makes sense but then the problem goes up to the upper function, where T does not extend DocumentSchema[]
tldr. you could provide the generic type when calling your function
like so
performMultiSearch<Foo>([1, 2, 3], searchParams);
but the function would return a Promise<MultiSearchResponse<DocumentSchema[]>>
yes but performMultiSearch exptect also something that extends DocumentSchema[]
ok, so T should be a DocumentSchema[] in the function as well