-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError with TS@5.1.3: Property 'hitsPerPage' does not exist on type 'IntrinsicAttributes & PlainSearchParameters' #5658
TypeError with TS@5.1.3: Property 'hitsPerPage' does not exist on type 'IntrinsicAttributes & PlainSearchParameters' #5658
Comments
I wonder if this is caused by PlainSearchParameters being extended from SearchOptions, but not manually retyping those keys? https://github.com/algolia/algoliasearch-helper-js/blob/develop/index.d.ts#L394 |
It seems the editor/typescript has trouble picking up the type of So perhaps its something to do with that |
Currently, I'm just re-exporting the import { SearchOptions } from "@algolia/client-search";
import {
Configure as ConfigureAlgolia,
ConfigureProps,
} from "react-instantsearch-hooks-web";
export const Configure = (props: ConfigureProps & SearchOptions) => (
<ConfigureAlgolia {...props} />
); |
Thanks for listing this workaround, we didn't find that option yet! |
in TypeScript 5.1.3, the check `any extends T` when T is any no longer evaluates to one branch of the conditional, but the union of both branches. This is fixed by using a "never possible to be true, unless T is any" condition as in https://stackoverflow.com/a/49928360/3185307 fixes algolia/instantsearch#5658 FX-2396
* fix(types): improve conditional for client version in TypeScript 5.1.3, the check `any extends T` when T is any no longer evaluates to one branch of the conditional, but the union of both branches. This is fixed by using a "never possible to be true, unless T is any" condition as in https://stackoverflow.com/a/49928360/3185307 fixes algolia/instantsearch#5658 FX-2396 * chore(dev): update typescript this showed the error before the previous commit as ``` test/types.ts:16:7 - error TS2345: Argument of type '{ query: string; }' is not assignable to parameter of type 'PlainSearchParameters'. Object literal may only specify known properties, and 'query' does not exist in type 'PlainSearchParameters'. 16 query: 'something fun', ~~~~~ Found 1 error in test/types.ts:16 error Command failed with exit code 2. ```
Hi @Haroenv, thanks for the fix! Do you have an ETA for a release where the fix is included? Have a great day! |
I've just released the fix in the helper, so if you re-update the dependencies, you will no longer have this issue. |
Thank you! |
Although automatic updates can already solve this issue on its own, an explicit update will prevent many more people seeing it. fixes #5658
Although automatic updates can already solve this issue on its own, an explicit update will prevent many more people seeing it. fixes #5658
…arch-helper-js#943) * fix(types): improve conditional for client version in TypeScript 5.1.3, the check `any extends T` when T is any no longer evaluates to one branch of the conditional, but the union of both branches. This is fixed by using a "never possible to be true, unless T is any" condition as in https://stackoverflow.com/a/49928360/3185307 fixes #5658 FX-2396 * chore(dev): update typescript this showed the error before the previous commit as ``` test/types.ts:16:7 - error TS2345: Argument of type '{ query: string; }' is not assignable to parameter of type 'PlainSearchParameters'. Object literal may only specify known properties, and 'query' does not exist in type 'PlainSearchParameters'. 16 query: 'something fun', ~~~~~ Found 1 error in test/types.ts:16 error Command failed with exit code 2. ```
Same issue on instantsearch.js |
@g-mero, are you on the latest version of everything? This issue was fixed a couple months ago downstream |
I've got a similar issue after migrating from v6 to v7. Packages: "react-instantsearch": "^7.4.1",
"react-instantsearch-core": "^7.4.1", Removed In a component I've got: import { Configure, InstantSearch, useInfiniteHits } from 'react-instantsearch' (previously this was imported from render: return (
<div>
<InstantSearch searchClient={searchClient} indexName={algoliaIndex}>
<Configure filters={`productType:"${parentExpedition.productType}"`} hitsPerPage={4} />
{/* irrelevant code removed */}
</InstantSearch>
</div>
) As mentioned above - the props type is Any ideas how to get this to work? I can see that the latest version (3.16.0) of |
I can't reproduce this in our examples, |
@Haroenv I just fixed this. Had this warning when
Adding I didn't know that was required - it wasn't before when using v6 at least. So maybe it should be added to the migration guide? (Perhaps it's already there and I missed it). |
It always was required, but in v6 there was no typescript types builtin. I believe v6 on DefinitelyTyped had a dependency on algoliasearch possibly though |
🐛 Current behavior
So this might be a bug with typescript, but it's the only library that broke when updating it so I'm going to create the bug report here.
When running with version
5.1.3
oftypescript
andreact-instantsearch-hooks-web
I get a type error on theConfigure
component, it appears it's no longer inferring theSearchOptions
correctly. Downgrading to version5.0.4
oftypescript
fixes the issue.🔍 Steps to reproduce
react-instantsearch-hooks-web@6.44.1 typescript@5.1.3
tsc --noEmit
Or checkout this repro https://stackblitz.com/edit/algolia-ts-bug-2mfs3u?file=app%2FSearchApp.tsx and run
npm run typecheck
in the terminal.Live reproduction
https://stackblitz.com/edit/algolia-ts-bug-2mfs3u?file=app%2FSearchApp.tsx
💭 Expected behavior
There should be no typescript error as with previous versions of typescript.
Package version
react-instantsearch-hooks-web@6.44.1, typescript@5.1.3
Operating system
Windows, Linux
Browser
Chrome
Code of Conduct
The text was updated successfully, but these errors were encountered: