jest-expect-message icon indicating copy to clipboard operation
jest-expect-message copied to clipboard

TS2304: Cannot find name 'JestMatchers'.

Open panzi opened this issue 1 year ago • 3 comments

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

panzi avatar Apr 26 '23 18:04 panzi

Do you have @types/jest package installed?

mrazauskas avatar Aug 28 '23 07:08 mrazauskas

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"]
}

mrazauskas avatar Aug 28 '23 07:08 mrazauskas

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

Fleetrun10 avatar Feb 02 '24 10:02 Fleetrun10