algolia / instantsearch

⚡️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/
MIT License
3.73k stars 527 forks source link

fix(types): make algoliasearch detection compatible with TS 5.4.5 #6244

Closed Haroenv closed 5 months ago

Haroenv commented 5 months ago

I can't manage to reproduce this locally, even if i update everything to 5.4.5, but in a fresh Next.js example (like https://codesandbox.io/s/47fy7c) hitsPerPage isn't accepted to Configure (because PlainSearchParameters is any)

This is I believe linked to https://github.com/microsoft/TypeScript/pull/56004, maybe also to https://github.com/sindresorhus/type-fest/issues/846 (although the case seems different).

Essentially before this change the types like ClientLiteV5 were evaluated to any instead of unknown, poisoning the entire type and turning everything into any.

The solution is to first check if typeof AlgoliaSearchLite is any, and if it is any we don't even evaluate the rest of teh type. Of course if it isn't any it works correctly for v5 still.

Again, unfortunately this isn't reproducible in this repo, even when every typescript version is updated to 5.4.5, but at least the error will be fixed

fixes #5989

codesandbox-ci[bot] commented 5 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1d6fd7a8cfa21d5fdd8c95bd4a3c7b845fcd6f67:

Sandbox Source
example-instantsearch-getting-started Configuration
example-react-instantsearch-getting-started Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-react-instantsearch-next-routing-example Configuration
example-vue-instantsearch-getting-started Configuration