当模块位于tsconfig路径中时,“找不到模块的声明文件”

时间:2020-05-20 17:43:19

标签: typescript

我在有角项目中使用markdown-it。我在markdown-it中同时安装了@types/markdown-itpackage.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打字?

0 个答案:

没有答案