Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

288
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda