Solvedtestcafe declare var test on global scope issue

Great to see TypeScript definition files with the package.
Unfortunately, we're having issues in a project that also uses Mocha. Both libraries have a test declaration on global scope, so TypeScript is throwing the following error:

Error TS2403: Subsequent variable declarations must have the same type.  Variable 'test' must be of type 'TestFn', but here has type 'ITestDefinition'.

In testcafe package:
declare var test: TestFn;

In @types/mocha
declare var test: Mocha.ITestDefinition;

It's global scope all over again.
I would prefer to import test from the Testcafe package. Or is there some other solution to this?

31 Answers

✔️Accepted Answer

having the same issue with jest and #testcafe -> both expose test as global type

Other Answers:

Guys, thanks a lot for your investigations and clarifications, now the problem is clear for me.

For now I suppose we can use the following solutions to resolve the problems:

  1. For the TypeScript compilation of the whole project - it can be resolved by tsconfig.json options:
  • skipLibCheck: true. It allows to ignore the variable declarations must have the same type error;
  • specifying types if it's suitable for the project (it can be super annoying, in projects with lot's of 3rd party libraries);
  • excluding TestCafe tests path since TestCafe compiles the tests before running.
  1. For running .ts tests via TestCafe - we can use the solution proposed by @Hotell, add the skipLibCheck: true option in our sources (it should fix the original issue, and we can publish it in the next minor version soon).

Meanwhile we will think about more fundamental solutions (like taking into account tsconfig.json in the project or something else)

More Issues: