Error catch of type unknown throw error with tsc
See original GitHub issueHi,
Just a little advice, while compiling in typescript 4.4.4, there is some errors :
node_modules/meilisearch/src/lib/http-requests.ts:71:21 - error TS2571: Object is of type 'unknown'.
71 const stack = e.stack
~
node_modules/meilisearch/src/lib/http-requests.ts:72:24 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'FetchError'.
72 httpErrorHandler(e, stack, constructURL.toString())
~
node_modules/meilisearch/src/lib/indexes.ts:259:11 - error TS2571: Object is of type 'unknown'.
259 if (e.errorCode === 'index_not_found') {
~
node_modules/meilisearch/src/lib/meilisearch.ts:94:11 - error TS2571: Object is of type 'unknown'.
94 if (e.errorCode === 'index_not_found') {
~
node_modules/meilisearch/src/lib/meilisearch.ts:97:11 - error TS2571: Object is of type 'unknown'.
97 if (e.type !== 'MeiliSearchCommunicationError') {
~
node_modules/meilisearch/src/lib/meilisearch.ts:98:39 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'MSApiError'.
98 throw new MeiliSearchApiError(e, e.status)
~
node_modules/meilisearch/src/lib/meilisearch.ts:98:42 - error TS2571: Object is of type 'unknown'.
98 throw new MeiliSearchApiError(e, e.status)
~
node_modules/meilisearch/src/lib/meilisearch.ts:100:11 - error TS2571: Object is of type 'unknown'.
100 if (e.type === 'MeiliSearchCommunicationError') {
~
node_modules/meilisearch/src/lib/meilisearch.ts:101:49 - error TS2571: Object is of type 'unknown'.
101 throw new MeiliSearchCommunicationError(e.message, e, e.stack)
~
node_modules/meilisearch/src/lib/meilisearch.ts:101:60 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'FetchError | Response'.
Type 'unknown' is not assignable to type 'Response'.
101 throw new MeiliSearchCommunicationError(e.message, e, e.stack)
~
node_modules/meilisearch/src/lib/meilisearch.ts:101:63 - error TS2571: Object is of type 'unknown'.
101 throw new MeiliSearchCommunicationError(e.message, e, e.stack)
~
node_modules/meilisearch/src/lib/meilisearch.ts:173:11 - error TS2571: Object is of type 'unknown'.
173 if (e.errorCode === 'index_not_found') {
~
Found 12 errors
My tsconfig (which has been specially modified to pass Request requirements (you can see the ‘DOM’ lib ) … 👎 )
{
"compilerOptions": {
"target": "es2020",
"lib": [
"esnext",
"DOM"
],
"module": "commonjs",
"sourceMap": true,
"outDir": "dist",
"rootDir": "./src/",
"strict": true,
"strictPropertyInitialization": false,
"moduleResolution": "node",
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
// "useUnknownInCatchVariables": false
}
}
Using useUnknownInCatchVariables will allow you to compile, however, it should be in the meilisearch tsconfig not in mine.
How you are considering adding this property.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Error object inside catch is of type unknown - Stack Overflow
TypeScript 4.4 introduced a new compiler option called useUnknownInCatchVariables that makes this behavior mandatory. It is false by default, ...
Read more >Get a catch block error message with TypeScript - Kent C. Dodds
TypeScript forces you to acknowledge you can't know what was thrown making getting the error message a pain. Here's how you can manage...
Read more >Object is of type 'unknown' Error in TypeScript | bobbyhadz
The "Object is of type unknown" error occurs when we try to access a property on a value that has a type of...
Read more >Playground Example - Unknown in Catch - TypeScript
Unknown in Catch. Because JavaScript allows throwing any value, TypeScript does not support declaring the type of an error ...
Read more >TypeScript: Narrow types in catch clauses - fettblog.eu
TypeScript will error with TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified. There are a couple of reasons ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks @alexisvisco ! I just made it work in the repo. I should have added
useUnknownInCatchVariablesin our tsconfig.json as well when upgrading to typescript 4.4.4. I come back to you asap 😃@bidoubiwa i give you an access to github.com/asvf-montagne/api (check your email)
Clone it, remove in the tsconfig the line
"useUnknownInCatchVariables": trueRun
yarn build😃