Signature mismatch x compile errors TS2339, TS2358, TS2339
bitbreakr opened this issue · comments
Description
The Meilisearch JavaScript library, meilisearch-js, is causing my TypeScript project to fail to compile due to some type signature errors in the file http-requests.ts.
I have cloned the repo, and I have precisely found where is the faulty code (see screenshot below)
When I try to compile my project, I get 3 errors that fall under TS2339, TS2358, TS2339:
Expected behavior
Errorless compilation
Current behavior
compile errors TS2339, TS2358, TS2339
ERROR in ./node_modules/meilisearch/src/http-requests.ts:24:37
TS2339: Property 'join' does not exist on type 'T[keyof T]'.
22 | return acc
23 | } else if (Array.isArray(value)) {
> 24 | return { ...acc, [key]: value.join(',') }
| ^^^^
25 | } else if (value instanceof Date) {
26 | return { ...acc, [key]: value.toISOString() }
27 | }
ERROR in ./node_modules/meilisearch/src/http-requests.ts:25:16
TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
23 | } else if (Array.isArray(value)) {
24 | return { ...acc, [key]: value.join(',') }
> 25 | } else if (value instanceof Date) {
| ^^^^^
26 | return { ...acc, [key]: value.toISOString() }
27 | }
28 | return { ...acc, [key]: value }
ERROR in ./node_modules/meilisearch/src/http-requests.ts:26:37
TS2339: Property 'toISOString' does not exist on type 'never'.
24 | return { ...acc, [key]: value.join(',') }
25 | } else if (value instanceof Date) {
> 26 | return { ...acc, [key]: value.toISOString() }
| ^^^^^^^^^^^
27 | }
28 | return { ...acc, [key]: value }
29 | }, {} as queryParams<T>)
Environment (please complete the following information):
- OS: [e.g. Debian GNU/Linux] MacOS Sonoma
- Meilisearch version: [e.g. v.0.20.0] Irrelevant information
- meilisearch-js version: [e.g v0.18.2] 0.35.0
- Browser: [e.g. Chrome version 90.0] Irrelevant information
- Node version: v18.17.1
Hello @bitbreakr
Thanks for the report and for finding where the issue is coming from ❤️
Feel free to open a PR to fix it
Hi @bitbreakr, I'm quite surprised to see these errors. Can you provide a test/pet project where this issue happens?
Also, if you ask this question in our Discord, you may find someone who shared this issue because it seems to be related to something particular on your project.
You have skipLibCheck
as false
(default value) in your tsconfig.json
. While in a world closer to perfect it would make sense to check libraries as well, we live in JS world, very far from perfect.
Many many packages don't keep their projects strictly type safe, and there are many other issues that can pop up because of different possible configurations and TS versions being used on library end versus client end.
Set this option to true
, you'll run into a lot of issues otherwise that you can't do anything about (not just with this package).
Never mind I can see the problem. You are importing the source files instead of the build files. Same issue in #1613 . In your screenshots you can see the path ./node_modules/meilisearch/src/(...)
so you are probably doing import { /* ... */ } from "meilisearch/src/whatever"
. Usually IDE auto imports do this.