打字稿无法解析类型

typescript unable to resolve type

我正在尝试在一个项目中使用 log4javascript,我看到该包在 node_modules/log4javascript/ 中确实有 log4javascript.d.ts,并且 package.json 在 "typings" 属性 但是在编译我的项目时它会抱怨:

S2307: Cannot find module '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"
    ]
}

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

如果您指定 target: "es2015",则模块系统将为 es2015。如果模块系统是 es2015,那么模块的分辨率默认为 clasic,它不会在 node_modules 中查找类型(如 here). You can find this in the docs for the compiler options

所述