我是TypeScript的新手,我只是想为pdf文件创建类型定义,而找不到有关此操作的资源。我在导入文件"Cannot find module <file_name.pdf> or its corresponding type declarations."
我想避免更改我的tsconfig.json
文件。
谢谢。
答案 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来解决了这个问题。