I'm building an application using typescript, node and electron.
I'm using jquery in the application and I've installed the @types/jquery package to have intellisense hints.
Next I created a test using mocha and spectron. Spectron makes use of webdriverio and exposes its API through some properties. I need to use these properties, so I installed @types/webdriverio to have intellisense hints.
Now, whenever I run the tsc tool to compile the project I get the following errors:
node_modules/@types/jquery/index.d.ts(36,15): error TS2451: Cannot redeclare block-scoped variable '$'.
node_modules/@types/webdriverio/index.d.ts(1898,18): error TS2451: Cannot redeclare block-scoped variable '$'.
node_modules/@types/webdriverio/index.d.ts(1899,18): error TS2451: Cannot redeclare block-scoped variable '$'.
The issue is that both packages declare a global $ variable. You can verify it also in their npm pages under "Global values":
https://www.npmjs.com/package/@types/jquery
https://www.npmjs.com/package/@types/webdriverio
What I don't understand is why tsc is trying to compile them together since I'm not using jquery and webdriverio in the same .ts file?
Also, even if I comment out the test, so I'm not referencing webdriverio in any place, when I run tsc I get the same errors. Probably tsc is compiling all the sources in node_modules/@types together. In fact, if I remove the node_modules/@types/webdriverio folder and run tsc again, I get no error (of course, as long as I keep the test code commented).
This is my tsconfig.json which is in the root of the project:
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"sourceMap": false,
"inlineSourceMap": true,
"inlineSources": true,
"declaration": false,
"outDir": "dist"
},
"include": [
"src/**/*"
]
}
All my source code is in the src directory. Tests are in src/test.
Is there any configuration I can make to keep webdriverio and jquery types separated at compile time? Also, I've seen some code examples written in js where they are used together: is this not feasible in typescript?