I'm using the pdf-lib package in a TypeScript project and wrote some wrapper code to use it in test automation. It worked fine. We decided to push this wrapper code to a shared project so others could use it too, but then the test breaks. After debugging, it seems that the transpiler may have caused the problem.
Pdf-lib's PDFDict
class has a get
method that returns a value based on the key parameter. Internally, it is calling this.dict.get(key)
where this.dict
is a javascript Map object. The key parameter can be of type any.
When running from our project,
this.dict.get(key)
returns FlateDecode
.
When referencing the shared project,
this.dict.get(key)
returns undefined
.
When running from our project, the keys in this.dict
and the key
object passed into get
are all PDFName
objects.
When running from the shared project, the keys in this.dict
are PDFName2
objects and the key
object passed in is a PDFName3
object.
If my assumption that get
is returning undefined because the Map key objects and the key passed in are 2 different types (PDFName2
vs PDFName3
), did the transpiler screw up here?
This sounds like the kind of bug you get when your code bundler is including multiple versions of a library; and that library isn't equipped to deal with that.
If you're using npm, check your lock file for multiple versions of one package and massage your package file so only one version is used. Resolving this could be very easy or impossible depending on what other dependencies you have.