Dave Thomas (pragdave)
02/08/2023, 5:34 PMimport { DocumentSchema, SearchResponse, SearchResponseHit }
from "../node_modules/typesense/src/TypeSense/Documents";
export interface PPDocument extends DocumentSchema {
title: string,
code: string,
id: string,
}
export type PPSearchResponse = SearchResponse<PPDocument>
export type PPSearchResponseHit = SearchResponseHit<PPDocument>
The first surprise is that the various Document
types don’t seem to be available at the top-level.
I then have code that performs the search, updating a preact state with the result:
export function doSearch(
client: SearchClient,
query: string,
setResultHolder: StateUpdater<PPSearchResponse>
) {
let searchParameters: SearchParams = { ... }
client
.collections<PPDocument>('ppbooks')
.documents()
.search(searchParameters, {})
.then((result) => { setResultHolder(result) })
.catch((error) => console.log(error))
}
The problem comes in the .then
clause. The result
parameter has been given the type SearchResponse<{}>
which is incompatible with the expected type of the parameter to setResultHolder
, which is SearchResponse<PPDocument>
.
I know I’m missing something fundamental. Can anyone show we what that is?
CheersJason Bosco
02/08/2023, 8:20 PMclient
.collections<PPDocument>('ppbooks')
.documents<PPDocument>()
.search(searchParameters, {})
.then((result) => { setResultHolder(result) })
.catch((error) => console.log(error))
Dave Thomas (pragdave)
02/08/2023, 9:35 PMdocuments
expected 0 type arguments…” 😪Jason Bosco
02/08/2023, 10:45 PMT
to new Collection
.
I wonder if it should read new Collection<T>
and that would fix this issue.
@Damian C any thoughts on this?