【发布时间】:2020-10-12 09:34:03
【问题描述】:
在我的项目中,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?
我可以在编译 xxx 模块时以某种方式强制顶级 tsc 使用 ./node_modules/xxx/tsconfig.json 吗?
编辑:
我的 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 个与模块相关的错误。
【问题讨论】:
-
它在反应项目中吗?
-
不,只是 node.js。
标签: typescript