Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
work with d.ts with a different folder for js (pdfjs-dist)

Currently pdfjs-dist https://github.com/mozilla/pdfjs-dist/tree/bd2a6cd87f9e0c3a9b3197d5d27acfb99886629b contains the d.ts and js files in separate folders:

https://github.com/mozilla/pdfjs-dist/blob/bd2a6cd87f9e0c3a9b3197d5d27acfb99886629b/types/src/display/node_utils.d.ts

https://github.com/mozilla/pdfjs-dist/blob/bd2a6cd87f9e0c3a9b3197d5d27acfb99886629b/lib/display/node_utils.js

If i import them with:

import { NodeCanvasFactory } from 'pdfjs-dist/types/src/display/node_utils';

it generates wrong js code:

const api_1 = require('pdfjs-dist/types/src/display/api');

Is it possible to properly map the d.ts along with js?

The result should be the following:

const api_1 = require("pdfjs-dist/lib/display/api");

I also tried to work with tsconfig.json

"paths": {
  "pdfjs-dist/types/src/*": ["./pdfjs-dist/lib/*"]
}

Full tsconfig.json

{
    "compilerOptions": {
        "target": "es2017",
        "module": "commonjs",
        "lib": [
            "es2017",
            "dom"
        ],
        "outDir": "dist",
        "rootDir": "src",
        "strict": true,
        "strictNullChecks": true,
        "noImplicitAny": true,
        "esModuleInterop": true,
        "resolveJsonModule": true,
        "forceConsistentCasingInFileNames": true,
        "declaration": true,
        "types": [
            "node",
            "jest"
        ],
        "sourceMap": true,
        "paths": {
            "pdfjs-dist/types/src/*": ["./pdfjs-dist/lib/*"]
        }
    },
    "include": [
        "src/**/*.ts"
    ],
    "exclude": [
        "node_modules", 
        "**/*.spec.ts"
    ]
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is the solution I came up with for the same problem. (In your question you were mixing api and node_utils, but will answer assuming you want to import node_utils).

First, create a declaration file named node_utils.d.ts (Note that the name of the file has to be the same as the module name).

In this file add the following:

declare module 'pdfjs-dist/lib/display/node_utils' {
    export * from 'pdfjs-dist/types/src/display/node_utils'
}

Now you can use pdfjs-dist/lib/display/node_utils when importing like below and Typescript will be pick up the declaration files. Unfortunately, this has to be done for every file you want to import that has typing in separate folders from the js files!

import { NodeCanvasFactory } from 'pdfjs-dist/lib/display/node_utils';
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!