.pdf文件的TypeScript类型声明

时间:2020-08-24 22:36:38

标签: typescript pdf types

我是TypeScript的新手,我只是想为pdf文件创建类型定义,而找不到有关此操作的资源。我在导入文件"Cannot find module <file_name.pdf> or its corresponding type declarations."

时收到此警告

我想避免更改我的tsconfig.json文件。

谢谢。

2 个答案:

答案 0 :(得分:3)

您可以简单地修改 tsconfig.js 以添加自定义类型,而不是修改 NPM 包,这比公认的解决方案更具前瞻性。

在您的 src 目录中创建typings 文件,命名为:types.d.ts(或其他)。插入:

declare module "*.pdf";

将此添加到您的 tsconfig:

"compilerOptions": {
    "typeRoots": ["./src/types"]
 ....
 }

答案 1 :(得分:1)

我通过在declare module '*.pdf';的{​​{1}}文件内使用global.d.ts并粘贴此答案https://github.com/facebook/create-react-app/issues/8021来解决了这个问题。