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.

Is the a TypeScript type definition available?

See original GitHub issue

Something on the order of "@types/pdf-lib".

If not, as embarrassed as I am to ask, how can I get VS Code to recognize the types in this excellent library?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
zackdotcomputercommented, Oct 6, 2020

OK having seen the conversation in #484 as well, I tried downgrading to the [deprecated] deno VSCode extension and it still did not work for me. I was still seeing the PDFDocument.load function have the type signature PDFDocument.load(pdf: any, options: any): any.

At this point, I was frustrated because I could see from the npm download that it should be working, so I spent too much time digging into this this morning.

Finally, I found a little note at the bottom of this page in Skypack’s (formerly Pika) documentation that you have to add ?dts at the end of a skypack/pika import to get the TS definitions for deno sent alongside the code. Adding that to the import solved the issue even with the latest, official plugin.

TDLR; import { PDFDocument } from 'https://cdn.skypack.dev/pdf-lib@^1.11.1?dts'; works

Opened PR #621 to update Pika to Skypack, update the version to latest, and add the ?dts flag for typing in the README to save future devs having to find this thread.

1reaction
Hopdingcommented, Aug 8, 2020

Hello @reselbob!

The TypeScript types are included in the pdf-lib NPM package. You do not need to install anything additional to get them. VSCode should just pick them up. If it’s not, the only cause I can think of is that you have plugins or configurations preventing it from doing so (e.g. the Deno plugin might cause this - haven’t tested it myself though).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Type Declarations - TypeScript
TypeScript automatically finds type definitions under node_modules/@types , so there's no other step needed to get these types available in your program. Your ......
Read more >
Surviving the TypeScript Ecosystem — Part 4 - Medium
The solution is to make a type definition file. A type definition file is a file that ends in “.d.ts”. It is a...
Read more >
Typescript Typings: The Complete Guide: @types Compiler ...
What are the multiple types of Typescript Type Definitions? How do I use libraries that don't have Type Definitions available?
Read more >
TypeScript: Type Definition Files - DEV Community ‍ ‍
All definition files are publicly available and placed in the Definitely Typed project in Github. It includes generated types for most of the ......
Read more >
Types and Type Declarations | Manual - Deno
When TypeScript is type checking a file, it only cares about the types for the ... available in the global namespace when importing...
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