jest-expect-message
jest-expect-message copied to clipboard
TS2304: Cannot find name 'JestMatchers'.
Bug
-
package
version: 1.1.0 -
node
version: 18.12.1 -
npm
version: 8.19.2
What you did:
jest.config.js
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts?$': 'ts-jest',
},
testMatch: [ "<rootDir>/src/test/**/*.tests.[jt]s?(x)" ],
transformIgnorePatterns: ['<rootDir>/node_modules/'],
setupFilesAfterEnv: ["jest-expect-message"],
};
tsconfig.json
{
"compilerOptions": {
"target": "es2020",
"lib": ["es2022"],
"module": "commonjs",
"outDir": "dist",
"sourceMap": true,
"experimentalDecorators": true,
"allowJs": true,
"noImplicitThis": true,
"strictNullChecks": true,
"moduleResolution": "node",
"strictPropertyInitialization": true,
"useUnknownInCatchVariables": true,
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"@types/*"
]
},
"types": ["node"]
},
"include": [
"src/**/*.ts",
"src/**/*.js"
],
"exclude": [
"node_modules"
],
"files": ["node_modules/jest-expect-message/types/index.d.ts"]
}
Then in my tests:
expect(response.success, "my message").toEqual(true);
Then when running npx tsc
I get:
node_modules/jest-expect-message/types/index.d.ts:7:8 - error TS2304: Cannot find name 'JestMatchers'.
7 ): JestMatchers<T>;
~~~~~~~~~~~~
src/test/tests/api.ts:1092:42 - error TS2554: Expected 1 arguments, but got 2.
1092 expect(response.success, "my message").toEqual(true);
~~~~~~~~~~~~
Do you have @types/jest
package installed?
Ah.. Might be you have, but it is not included in the "types"
list (i.e. not visible for TypeScript):
{
"compilerOptions": {
- "types": ["node"]
+ "types": ["jest", "node"]
}
Thread's dead, but for anyone with the same issue, I did find adding interface JestMatchers<T> extends Matchers<T> {}
seemed to fix Intellisense, since Matchers seems to be what's showing up in @types/jest