question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error catch of type unknown throw error with tsc

See original GitHub issue

Hi,

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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bidoubiwacommented, Nov 2, 2021

Thanks @alexisvisco ! I just made it work in the repo. I should have added useUnknownInCatchVariables in our tsconfig.json as well when upgrading to typescript 4.4.4. I come back to you asap 😃

0reactions
alexisviscocommented, Nov 2, 2021

@bidoubiwa i give you an access to github.com/asvf-montagne/api (check your email)

Clone it, remove in the tsconfig the line "useUnknownInCatchVariables": true
Run yarn build 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found