typescript - 打字稿忽略 node_module 的 tsconfig
问题描述
在我的项目中,tsconfig.json
我选择了选项strict=true
(启用所有严格的类型检查选项)。
当我添加时,import { sso } from 'node-expose-sspi';
我从 tsc 收到大约 60 个错误。
例如:
src/sso/auth.ts line 88 waitForReleased accepts string but cookieToken is string | undefined
我注意到,在 node-expose-sspi tsconfig 中只有noImplicitAny=true
,这意味着其他严格检查选项为假。由于直接在 node-expose-sspi 文件夹中运行 tsc 不会产生错误,但它从我的项目文件夹中失败。
但是为什么 typescript 编译器会忽略特定于模块的 tsconfig.json?
./node_modules/xxx/tsconfig.json
我可以在编译 xxx 模块时以某种方式强制使用顶级 tsc吗?
编辑:
我的 tsconfig.json:
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"outDir": "./dist/",
"rootDir": "./",
"removeComments": true,
"noEmitOnError": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
}
}
和 server.ts:
import express = require('express');
import { sso } from 'node-expose-sspi';
const app = express();
app.use(sso.auth());
app.use((req, res, next) => {
res.json({
sso: req.sso,
});
});
app.listen(3001, () => console.log('Server started on port 3001'));
编辑:我已将 server.ts 更改为node-expose-sspi中 exaple 的精确副本。
对不起,我在最初的问题中犯了错误。当我使用时,const { sso } = require('node-expose-sspi');
我不会从打字稿中得到错误。事实上,TS 完全忽略了这个模块,我得到了错误:
app.use((req, res, next) => {
res.json({
sso: req.sso,
});
});
在线req.sso
:Property 'sso' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs>'.
但是,一旦我更改为import { sso } from "node-expose-sspi";
我得到 62 与模块相关的错误。
解决方案
tsconfig
在文件中添加这个
"exclude": [
"node_modules"
]
推荐阅读
- react-native - 谷歌标签管理器电子商务分析反应原生
- javascript - 如何从不同的 HTML 文件调用模式
- office365 - SCCM 卸载 Project Pro,卸载后仍检测到应用程序
- java - 在数组中的每个第二个元素之后添加数据
- ios - 快速将 FSCalendar 转换为伊斯兰 Umm Al-qura 日历
- reactjs - 纱线安装删除几个包
- python-3.x - 如何在python中停止它之外的函数
- teamcity - 为什么 Teamcity 无法识别机器人命令?
- postgresql - 用户“postgres”的密码身份验证失败,用户“postgres”没有密码
- html - 使用字段集和标签为 HTML 表单设置样式以具有 3 列布局