我正在开发一个使用自定义字体的 React 项目。我有三个包含它们的 .otf 文件,我需要通过 font-face 添加它们。问题是打字稿抱怨:
Cannot find module '../../assets/fonts/AvenirLTStd-Black.otf' or its corresponding type declarations.ts(2307)
即使我有声明文件 custom.d.ts
工作:
import "styled-components";
declare module "styled-components" {
export interface DefaultTheme {
colors: {
gold: "#FFD04E";
text: "#494646";
disabled: "#E1E1E1";
background: "#FCFCFC";
};
}
}
declare module "*.otf";
我按如下方式导入模块:
import Avenir from "../../assets/fonts/AvenirLTStd-Black.otf";
这是我的tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["src", "custom.d.ts"]
}
我错过了什么?
如果我需要上传更多文件,请告诉我