Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

fix(types): improve conditional for client version #943

Merged
merged 2 commits into from
Jun 13, 2023
Merged

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Jun 13, 2023

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

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
@Haroenv Haroenv requested review from a team, dhayab and FabienMotte and removed request for a team June 13, 2023 15:49
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 13, 2023

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 ae94f98:

Sandbox Source
javascript-helper-app Configuration
InstantSearch.js Configuration

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.
```
@Haroenv
Copy link
Contributor Author

Haroenv commented Jun 13, 2023

This test case was already covered in test/types.ts and failed without intervention in 5.1.3, updated in ae94f98

@Haroenv Haroenv merged commit 6c22185 into develop Jun 13, 2023
@Haroenv Haroenv deleted the fix/types-client branch June 13, 2023 16:19
Haroenv added a commit that referenced this pull request Jun 14, 2023
 * fix(types): improve conditional for client version (#943) 6c22185
dhayab pushed a commit to algolia/instantsearch that referenced this pull request Jul 10, 2023
…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.
```
dhayab pushed a commit to algolia/instantsearch that referenced this pull request Jul 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants