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.

TypeScript compiler throws errors in cbor.d.ts

See original GitHub issue

I was trying to upgrade from cbor v5 to v6, but ran into compiler errors from types/lib/cbor.d.ts on my TypeScript project.

A quick reproduction looks like this:

  • npm init a project
  • Install dependencies:
    npm i cbor
    npm i -D typescript @types/node
    
  • Create index.ts and add import * as cbor from 'cbor' to it
  • Run npx tsc index.ts

I’d expect this to compile, but instead TypeScript outputs the following errors (collapsed due to size):

TypeScript output
➤ npx tsc index.ts
node_modules/cbor/types/lib/cbor.d.ts:16:10 - error TS2304: Cannot find name 'comment'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
            ~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:10 - error TS2552: Cannot find name 'comment'. Did you mean 'Commented'?

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
            ~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:19 - error TS2304: Cannot find name 'decodeAll'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                     ~~~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:30 - error TS2304: Cannot find name 'decodeFirst'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                                ~~~~~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:43 - error TS2304: Cannot find name 'decodeAllSync'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                                             ~~~~~~~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:58 - error TS2304: Cannot find name 'decodeFirstSync'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                                                            ~~~~~~~~~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:75 - error TS2304: Cannot find name 'diagnose'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                                                                             ~~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:85 - error TS2304: Cannot find name 'encode'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                                                                                       ~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:93 - error TS2304: Cannot find name 'encodeCanonical'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                                                                                               ~~~~~~~~~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:110 - error TS2304: Cannot find name 'encodeOne'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                                                                                                                ~~~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:121 - error TS2304: Cannot find name 'encodeAsync'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                                                                                                                           ~~~~~~~~~~~

node_modules/cbor/types/lib/cbor.d.ts:16:134 - error TS2304: Cannot find name 'decodeFirstSync'.

16 export { comment, decodeAll, decodeFirst, decodeAllSync, decodeFirstSync, diagnose, encode, encodeCanonical, encodeOne, encodeAsync, decodeFirstSync as decode };
                                                                                                                                        ~~~~~~~~~~~~~~~

node_modules/cbor/types/lib/commented.d.ts:99:25 - error TS2306: File '<snip>/node_modules/@types/node/stream.d.ts' is not a module.

99 import stream = require("node/stream");
                           ~~~~~~~~~~~~~

node_modules/cbor/types/lib/decoder.d.ts:142:25 - error TS2306: File '<snip>/node_modules/@types/node/stream.d.ts' is not a module.

142 import stream = require("node/stream");
                            ~~~~~~~~~~~~~

node_modules/cbor/types/lib/diagnose.d.ts:48:25 - error TS2306: File '<snip>/node_modules/@types/node/stream.d.ts' is not a module.

48 import stream = require("node/stream");
                           ~~~~~~~~~~~~~

node_modules/cbor/types/lib/encoder.d.ts:224:25 - error TS2306: File '<snip>/node_modules/@types/node/stream.d.ts' is not a module.

224 import stream = require("node/stream");
                            ~~~~~~~~~~~~~

node_modules/cbor/types/lib/map.d.ts:30:28 - error TS2314: Generic type 'Iterable<T>' requires 1 type argument(s).

30     constructor(iterable?: Iterable<any, any>);
                              ~~~~~~~~~~~~~~~~~~

node_modules/cbor/types/vendor/binary-parse-stream/index.d.ts:26:25 - error TS2306: File '<snip>/node_modules/@types/node/stream.d.ts' is not a module.

26 import Stream = require("node/stream");
                           ~~~~~~~~~~~~~


Found 18 errors.

I can use the skipLibCheck option to avoid the errors, but cbor itself still wouldn’t have type information when I went to use it in my code.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
hildjjcommented, Jan 18, 2021

Great catch on decodeFirst. I used the copy/paste anti-pattern to create that bug. If you update it should be fixed.

1reaction
hildjjcommented, Jan 18, 2021

6.0.1 published. cbor-cli to follow as soon as i fix whatever i broke there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSC tries to compile my .d.ts files, then spits out errors from ...
When I compile my project using tsc it tries to compile my .d.ts files event though the /typings folder is excluded in my...
Read more >
Typescript doesn't throw error in .d.ts files - Stack Overflow
In my case, this was happening because I had "skipLibCheck": true in my tsconfig.json . Turning it to false fixed this problem.
Read more >
TypeScript errors and how to fix them
A list of common TypeScript errors and how to fix them.
Read more >
TSConfig Reference - Docs on every TSConfig option
When set to true, TypeScript will raise an error when a class property was declared but not set in the constructor. ts. class...
Read more >
Understanding TypeScript's “Compilation Process” & the ...
The .d.ts file is a TypeScript declaration file, ... If a file does not belong to the rootDir , the TypeScript compiler throws...
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