0

I'm trying to set up testing on my TypeScript SPA using webdriver.io. I set up wdio but could not compile the typescript because of various type conflicts caused by new types introduced by wdio.

For example, wdio introduces $ which conflicts with $ in jQuery:

node_modules/@types/jquery/misc.d.ts:6536:15 - error TS2451: Cannot redeclare block-scoped variable '$'.

6536 declare const $: JQueryStatic;
                   ~

  node_modules/@wdio/sync/webdriverio.d.ts:38:18
    38 declare function $(selector: string | Function): WebdriverIO.Element;
                        ~
    '$' was also declared here.

Node also introduces various conflicts:

node_modules/@types/node/index.d.ts:66:11 - error TS2300: Duplicate identifier 'IteratorResult'.

66 interface IteratorResult<T> { }
             ~~~~~~~~~~~~~~

  node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6
    41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
            ~~~~~~~~~~~~~~
    'IteratorResult' was also declared here.

and, more subtley, the Node types change the return type of a setTimeout

wwwroot/app/shared/lib/decorators/debounce.ts:36:17 - error TS2345: Argument of type 'Timer' is not assignable to parameter of type 'number'.

36                 setTimeout(method.bind(this, ...args), milliseconds)

I definitely want to use TypeScript to build both the tests and the app, as I want to leverage the app types in the tests. I assume this means I need to build them in tandem.

Do any workarounds for this exist?

Matthew James Davis
  • 12,134
  • 7
  • 61
  • 90
  • Are you trying to use both jQuery $ and wdio $ in the same code? If not, you can introduce finer-grained `tsconfig.json`s to control what libraries are loaded for each part of your project. – jonrsharpe Aug 25 '20 at 16:32
  • No, I am not. I'd be interested to see the approach you're suggesting. Would it cause problems if I then try to import my app code into my test code? Won't the types conflict? – Matthew James Davis Aug 25 '20 at 17:21

0 Answers0