Repository navigation
[@types/html-to-pdfmake] window requires jsdom's DOMWindow, pins @types/pdfmake to 0.2, and types showHidden as showhidden
#75834
Unanswered
Chaosnico9000
asked this question in
Issues with a @types package
Replies: 1 comment
|
Thanks for the discussion about " |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Package: @types/html-to-pdfmake 2.4.5 (
types/html-to-pdfmakeonmaster@ 8442c3d, unchanged since 5734314). Library: html-to-pdfmake 2.5.36 (@ af6153b).Four mismatches between the declarations and what the library does. All four show up with one call site, see the script below.
1.
windowmust be a jsdomDOMWindowThe option is typed as
import("jsdom").DOMWindow(index.d.ts L11). The library only stores the window (index.js L45) and constructs itsDOMParser(L125); nothing else is read from it. Any other DOM implementation on the server (happy-dom, linkedom, ...) works at runtime but is rejected by the type, and every consumer gets@types/jsdominstalled through thedependenciesof this package.2.
@types/pdfmakeis pinned to^0.2.0package.json L10 was changed from
*to^0.2.0in #74337, when@types/pdfmakemoved to 0.3. A project on pdfmake 0.3 with@types/pdfmake0.3 therefore gets a second, nested@types/pdfmake0.2.13, and theContentreturned byhtmlToPdfmake()is not assignable to the project's ownContent. The package's own test file compiles unchanged against@types/pdfmake0.3.3 (checked with its tsconfig plusesModuleInterop, TypeScript 5.9.3), so the pin looks unnecessary.3.
showhiddeninstead ofshowHiddenThe declaration has
showhidden(L24). The library readsoptions.showHidden(index.js L50), and has done so since the option was added in 2.4.10. So the typed spelling is silently ignored and the working spelling is a type error.4.
imagesByReference: truereturns{ content, images }The return type is always
Content(L48), but withimagesByReferencethe library returns{ content, images }(index.js L1271-L1277). This one is already reported in discussion #66867; listed here because the fix below covers it too.Also missing from the options, going by the library's JSDoc and source (not checked beyond reading):
collapseMargins,removeTagClasses(L49-L51) andcustomTag(L696-L698).Reproduction
package.jsondependencies:html-to-pdfmake@2.5.36,@types/html-to-pdfmake@2.4.5,pdfmake@0.3.12,@types/pdfmake@0.3.3,happy-dom@21.0.4,typescript@5.9.3. tsconfig:strict,module/moduleResolution: nodenext,types: [].tsc -p .:The same calls at runtime (bun 1.4.4, happy-dom window):
(input for the
showHiddenlines:<p>shown</p><p style="display:none">hidden</p>)Suggested fix
window?: { DOMParser: new() => { parseFromString(string: string, type: "text/html"): unknown } }, and drop@types/jsdomfromdependencies. jsdom'sDOMWindowstill fits this type."@types/pdfmake": "^0.3.0"(or back to*).showhiddentoshowHidden; addcollapseMargins,removeTagClasses,customTag.imagesByReference: truereturning{ content: Content; images: Record<string, string | ImageDefinition> }.With those changes applied to a local copy of
index.d.ts, the script above compiles without errors, and so does a jsdom window (new JSDOM("").window). The package's test file then needs two updates, because it encodes points 3 and 4: it passesshowhidden: trueand assigns animagesByReference: trueresult toContent.I can open a PR with this if that is the preferred route.
Environment
All reactions