typescript - 打字稿无法解析类型
问题描述
我正在尝试在项目中使用 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"
]
}
解决方案
推荐阅读
- c++ - 如果可能,C++ 是否总是更喜欢右值引用转换运算符而不是 const 左值引用?
- regex - 仅当它位于行尾时才匹配文件中的单词的正则表达式
- java - JAX-WS: Soap-Client - 为什么需要 WSDL 来初始化存根
- javascript - _.groupBy 但 _.sort 先
- file - 将文件复制到新创建的目录并重命名问题
- ios - iOS didRegisterForRemoteNotificationsWithDeviceToken 获取令牌字符串?
- java - Spring 单元测试是如何使用基于注解的实现来完成的
- android - 不更新表时使用 onUpgrade 的正确方法?
- dc.js - DC.js 禁用选择菜单
- java - 线程顺序执行中的 RxJava newbee 问题