打字稿无法解析类型

时间:2018-11-13 13:23:17

标签: typescript typescript-typings log4javascript

我正在尝试在项目中使用log4javascript,我发现该软件包确实在node_modules / log4javascript /中存在log4javascript.d.ts,并且package.json确实在“ typings”属性中引用了它,但是在编译时抱怨的项目:

  

S2307:找不到模块'log4javascript'

我正在使用以下模块导入模块:

import {getLogger } from 'log4javascript';

据我所知,不需要使用以下方法分别安装类型:

  

npm install @ types / log4javascript

,因为已经存在键入内容。但是,如果有以下情况,我不确定如何使用模块类型和方法:

"noImplicitAny": true,

在我的tsconfig.json中设置

我的tsconfig.json看起来像:

{
    "compileOnSave": true,
    "compilerOptions": {
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "target": "es2015",
        "declaration": true
    },
    "include": [
        "static/js/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

1 个答案:

答案 0 :(得分:2)

您需要在tsconfig.json中指定"moduleResolution": "node"选项

如果您指定target: "es2015",则模块系统将为es2015。如果模块系统为es2015,则模块的分辨率默认为clasic,对于类型(如here所述),该分辨率不会在node_modules中查找。您可以在编译器options

的文档中找到此内容
相关问题