Typescript: How to manage dependencies with conflicting type declarations?
Asked Answered
W

1

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?

Without answered 9/5, 2018 at 20:19 Comment(5)
Two libraries are claiming to own the same global variable - which will actually be the case at run-time?Salesperson
@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.Without
@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 notWithout
@Without have you managed to find a solution after all this time ?Littoral
@Littoral not really, though I'm sure there is one. I haven't worked on a typescript codebase in some time now.Without
G
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"
  ]
}
Grillroom answered 15/8, 2018 at 19:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.