meilisearch-js-plugins icon indicating copy to clipboard operation
meilisearch-js-plugins copied to clipboard

InstantMeiliSearchInstance is not assignable to type 'SearchClient | CompositionClient'

Open Strift opened this issue 10 months ago • 13 comments

Summary

The instantsearch client (@meilisearch/instant-meilisearch) typing is incompatible with the latest release of instantsearch.

Context

Description

The types expected by the latest versions of react-instantsearch and the client returned by @meilisearch/instant-meilisearch and meilisearch do not match.

Versions used:

const { searchClient } = instantMeiliSearch('url', 'apiKey')
return (
  <InstantSearch indexName="index" searchClient={searchClient}>
)

Current behavior

Since the new update of the library, a type error occurs when passing the search client returned by instant-meilisearch to the InstantSearch component.

Error:
Type 'InstantMeiliSearchInstance' is not assignable to type 'SearchClient | CompositionClient'.

(The searchClient prop expects a SearchClient | CompositionClient type)

Expected behavior

No error should occur.

Environment (please complete the following information):

  • "meilisearch": "^0.48.2",
  • "@meilisearch/instant-meilisearch": "^0.24.0",
  • "react-instantsearch": "^7.15.3",

Strift avatar Feb 07 '25 09:02 Strift

Hi @flevi29, I haven't gotten time to investigate. Could this be related to the updates we performed on the generated types?

Strift avatar Feb 07 '25 09:02 Strift

I'm going to investigate it, but I doubt it's us, we're probably just out of date. Unless previous versions worked fine, but even then it's possible. One thing's for sure, the error message is not being very helpful.

flevi29 avatar Feb 07 '25 13:02 flevi29

Apparently function search doesn't exist anymore.

Image

flevi29 avatar Feb 08 '25 13:02 flevi29

I'm actually not sure what's the problem here, Algolia types are such a cluster****, I've opened #1378, for now I'm leaving it.

flevi29 avatar Feb 08 '25 13:02 flevi29

@Strift Okay, I've taken a look at the source code. There really isn't a search and searchForFacetValues anymore. There's only scheduleSearch now, and it doesn't take any arguments. This requires major changes in the code, but I don't really want to work on this that much. Maybe for now we can require an older instantsearch.js, and when you or anyone else from the team has time to investigate and adapt to the newer version of Instantsearch we'll switch to it.

flevi29 avatar Feb 09 '25 09:02 flevi29

Thanks for the investigation @flevi29. I'll see how I can prioritize this after the v1.13 release of Meilisearch.

Strift avatar Feb 10 '25 02:02 Strift

@flevi29 this is how i am currently using it (search() and other func are inside .client)

searchClient={{
                    search: searchClient?.client?.search,
                    searchForFacetValues: searchClient?.client?.searchForFacetValues,
                    initIndex: searchClient?.client?.initIndex,
                    addAlgoliaAgent: searchClient?.client?.addAlgoliaAgent,
                    getRecommendations: searchClient?.client?.getRecommendations,
                    ...searchClient
                }}

DhifMlak avatar Feb 20 '25 11:02 DhifMlak

This is not only issue of the latest instantsearch. I ran into this issue with react-instantsearch 7.13.9 as well after updating to 0.24.0

petr-hajek avatar Mar 11 '25 17:03 petr-hajek

What is the last compatible instant search version? I'm also running into this issue.

kaylanhua avatar Apr 05 '25 22:04 kaylanhua

So we should forget about instant search for while ? As @kaylanhua said, maybe there would be a workaround by downgrading the depencies to the last compatible version ?

tangorri avatar Apr 17 '25 13:04 tangorri

So we should forget about instant search for while ? As @kaylanhua said, maybe there would be a workaround by downgrading the depencies to the last compatible version ?

I just have a ts error, but everything works, the latest version.

lpkobamn avatar Apr 21 '25 16:04 lpkobamn

Hi folks, just to clarify, someone coming from the outside...

  1. Do we have this typing issue since which meilisearch-js version?
  2. Is this issue due to a meilisearch-js upgrade or an instantsearch one?

CC: @Strift if this is preventing people from using the library (type issues can be very bad for the DX) we should give this a higher priority :)

brunoocasali avatar Jun 19 '25 21:06 brunoocasali

I have this typing issue with the latest release of "@meilisearch/instant-meilisearch". downgrade "@meilisearch/instant-meilisearch" to "0.23.0" is ok. the working config:

  • "@meilisearch/instant-meilisearch": "0.23.0",
  • "next": "latest",
  • "react": "latest",
  • "react-dom": "latest",
  • "react-instantsearch": "latest",
  • "react-instantsearch-nextjs": "^0.4.9",

vulcangz avatar Jun 20 '25 09:06 vulcangz