我在有角项目中使用markdown-it。我在markdown-it
中同时安装了@types/markdown-it
和package.json
作为依赖项。我想在构建捆绑包时提取缩小的文件,因此我在tsconfig的paths
数组中添加了一个条目:
[tsconfig.json]
{
"compilerOptions": {
"importHelpers": true,
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"downlevelIteration": true,
"target": "es2015",
"noUnusedLocals": true,
"noImplicitAny": true,
"noImplicitThis": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"alwaysStrict": true,
"typeRoots": [
"node_modules/@types",
"../../node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"baseUrl": ".",
"paths": {
"markdown-it": [
"node_modules/markdown-it/dist/markdown-it.min.js",
]
},
"module": "esnext"
},
"angularCompilerOptions": {
"enableIvy": false
},
"exclude": [
"node_modules",
"tmp"
]
}
但是,当我在组件打字稿文件中执行以下操作时:
import MarkdownIt from 'markdown-it';
我收到此错误:
Could not find a declaration file for module 'markdown-it'. '...../node_modules/markdown-it/dist/markdown-it.min.js' implicitly has an 'any' type.
2 import MarkdownIt from 'markdown-it';
没有tsconfig
中的路径条目,就不会发生该错误,但是显然它不会像我想要的那样拉入缩小的文件。如何使用paths
别名,同时还告诉打字稿使用@types/markdown-it
打字?