Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda