6

I have the error: Subsequent variable declarations must have the same type

This is occurring because two of my dependencies, both of which I need; declare the same type.

Jest :/node_modules/@types/jest/index.d.ts => declare var test: jest.

testcafe node_modules/testcafe//ts-defs/index.d.ts => declare var test: TestFn;

My project is a react/redux project using webpack, babel and obviously Typescript.

The error occurs when I am running my dev server via npm start which uses webpack-dev-server. It also creates a problem when I run jest since it uses testcafe's version of the declared Test type.

How can this be resolved?

micahblu
  • 4,924
  • 5
  • 27
  • 33
  • Two libraries are claiming to own the same global variable - which will actually be the case at run-time? – Ryan Cavanaugh May 09 '18 at 20:31
  • @RyanCavanaugh this occurs when I am running my dev server via `npm start ` which uses `webpack-dev-server`. It also creates a problem when I run `jest` since it uses `testcafe`'s version of Test type. – micahblu May 09 '18 at 20:43
  • @RyanCavanaugh Neither when I run `npm start` which is running `webpack-dev-server` since jest nor testcafe are being executed. I think what is happening is typescript is checking all index.d.ts files associated with the project regardless if they are being used or not – micahblu May 10 '18 at 01:05
  • @micahblu have you managed to find a solution after all this time ? – TOPKAT Jan 30 '23 at 16:41
  • @TOPKAT not really, though I'm sure there is one. I haven't worked on a typescript codebase in some time now. – micahblu Feb 19 '23 at 17:59

1 Answers1

2

Per discussion here: https://github.com/DevExpress/testcafe/issues/1537

You can exclude the end to end test files that TestCafe looks for in your local tsconfig.json file.

It's a hack but it worked for me.

Example tsconfig.json file, assuming all your end to end test modules are under test/e2e:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "sourceMap": true,
    "strict": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true
  },
  "exclude": [
    "test/e2e"
  ]
}
benjaminz
  • 3,118
  • 3
  • 35
  • 47