'@ts-expect-error' TypeScript 指令在 Jest 测试中不起作用
我正在使用 nx 和 axiom 创建一个 express 应用程序。现在,我正在尝试使用 //@ts-expect-error 指令,但我从终端和编辑器都收到了错误:未使用的 '@ts-expect-error' 指令。
这是我的测试:
describe('apps', () => {
it('should return an error if you return things not in the ts
definition', () => {
expect(() => {
appNotify.get('/v1/notify/healthcheck', ( res) => {
//@ts-expect-error - notExistingProperty shold not be allowed
res.json({
notExistingProperty: true,
message: 'Welcome to notify!'
});
});
}).toThrow();
});
});
这是我的 tsconfig :
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": ".",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"module": "esnext",
"lib": ["es2017", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"@notify/logger": ["libs/logger/src/index.ts"],
"@notify/notify-redis-client": ["libs/notify-redis-client/src/index.ts"]
},
"strict": true
},
"exclude": ["node_modules", "tmp"]
}
我的 TypeScript 版本是 4.9.5
我尝试在 tsconfig 中启用 checkJS,但没有任何改变。