mattphillips/jest-expect-message

TS2304: Cannot find name 'JestMatchers'.

panzi opened this issue · 3 comments

panzi commented

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);
                                              ~~~~~~~~~~~~