I'm trying to port my JS WDIO project ot TypeScript
I have faced the issue when during the development TypeScript is not recognizing my Nodejs global variables declared in before hook in my WDIO config:
...
let chai = require('chai');
...
before: async function (capabilities, specs) {
//setting global variables
global.foo = "bar"
global.expect= chai.expect;
global.helpers = require("../helpers/helpers");
// ... etc.
// ... etc.
},
I came across different SO topics but seems like they are not relevant since the approach here is bit different (because of the before hook)...
I even have manged to get it working at some point by creating global.d.ts with something inside like:
declare module NodeJS {
interface Global {
foo: string
}
}
But after this typescript stopped recognizing WDIO types lik browser, $ etc.
And also with this approach I had to use global.foo in my tests meaning I have to change hundreds of occurrences of foo.
How can I migrate my project to TypeScript and continue using my global variables from the before hook?