Skip to content
Discussion options

You must be logged in to vote

This is actually related to the search client, not InstantSearch, but it's because results could be of type default or facet, you can cast it: guardSearchResponse(lotResultsQuery.data?.results[0]) with

// algoliasearch v4
import { SearchResponse, MultipleQueriesResponse } from "algoliasearch";

function guardSearchResponse<TObject>(
  result: MultipleQueriesResponse<TObject>['results'][number]
): result is SearchResponse<TObject> {
  return 'hits' in result;
}
// algoliasearch v5
import type { SearchResponse, SearchResult } from 'algoliasearch';

function guardSearchResponse<TObject>(
  result: SearchResult
): result is SearchResponse<TObject> {
  return 'hits' in result;
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@nikoewe
Comment options

@Haroenv
Comment options

@nikoewe
Comment options

Answer selected by JSShant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants