We are facing an issue while trying to set up Mocha and Jest with types in one project. Our strict typecheck is causing conflicts with global types, leading to errors.
One approach we tried was creating an ambiguous module declaration by only defining Mocha in the 'types' section of the 'tsconfig' file. We attempted to remove Jest's declaration, but that only provided a partial solution. Disabling strict typecheck or lib checking is not an option for us.
We expected everything to function correctly, but instead, we encountered the following errors:
node_modules/@types/jest/index.d.ts(29,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'beforeEach' must be of type 'HookFunction', but here has type 'Lifecycle'.
node_modules/@types/jest/index.d.ts(31,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'afterEach' must be of type 'HookFunction', but here has type 'Lifecycle'.
node_modules/@types/jest/index.d.ts(32,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'describe' must be of type 'SuiteFunction', but here has type 'Describe'.
node_modules/@types/jest/index.d.ts(34,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'xdescribe' must be of type 'PendingSuiteFunction', but here has type 'Describe'.
node_modules/@types/jest/index.d.ts(35,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'it' must be of type 'TestFunction', but here has type 'It'.
node_modules/@types/jest/index.d.ts(37,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'xit' must be of type 'PendingTestFunction', but here has type 'It'.
node_modules/@types/jest/index.d.ts(38,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'test' must be of type 'TestFunction', but here has type 'It'.
node_modules/@types/node/globals.d.ts(926,15): error TS2430: Interface 'Global' incorrectly extends interface 'MochaGlobals'.
Types of property 'describe' are incompatible.
Type 'Describe' is not assignable to type 'SuiteFunction'.
Types of property 'only' are incompatible.
Type 'DescribeBase' is not assignable to type 'ExclusiveSuiteFunction'.
Type 'void' is not assignable to type 'Suite'.
Even when removing all types from Jest, the same error persists:
node_modules/@types/node/globals.d.ts(926,15): error TS2430: Interface 'Global' incorrectly extends interface 'MochaGlobals'.
Types of property 'describe' are incompatible.
Type 'Describe' is not assignable to type 'SuiteFunction'.
Types of property 'only' are incompatible.
Type 'DescribeBase' is not assignable to type 'ExclusiveSuiteFunction'.
Type 'void' is not assignable to type 'Suite'.