wdio-intercept-service icon indicating copy to clipboard operation
wdio-intercept-service copied to clipboard

Namespace 'global.WebDriver' has no exported member 'Client' after updating WDIO to v7

Open DrewciferB opened this issue 3 years ago • 8 comments

Hi there, I'm getting the following error on compile after updating WDIO to v7. Everything works fine under v6.

node_modules/wdio-intercept-service/types/wdio-intercept-service.d.ts:60:59 - error TS2694: Namespace 'global.WebDriver' has no exported member 'Client'.
60 type AsyncSync<T> = WebdriverIO.Browser extends WebDriver.Client

It seems that intercept service is defining a type based on an extension of Webdriver.Client, but the global namespace no longer exports Client as an interface in WDIO v7? I admit I'm quite out of my depth here, so apologies if I've missed something basic.

I have Intercept v4.2.1 specified in package.json: "wdio-intercept-service": "^4.2.1",

Here are my tsconfig.json types "types": ["node", "webdriverio/sync", "@wdio/mocha-framework", "wdio-intercept-service"]

I notice that the types changed in v7 from @wdio/sync to webdriverio/sync, not sure if that has anything to do with this but the error seems to be happening around code that is concerned with detecting sync mode, so I thought it might be relevant (from wdio-intercept-service/types/wdio-intercept-service.d.ts):

/**
 * Convert T to T or Promise<T> depending if `@wdio/sync` is being used or not.
 */
type AsyncSync<T> = WebdriverIO.Browser extends WebDriver.Client
  ? T
  : Promise<T>;

Even installing a brand new v7 webdriver project into a blank folder and then adding the intercept service still triggered this error, and it also occurs regardless of whether @wdio/sync is installed or not. Any help much appreciated 👍

DrewciferB avatar Feb 09 '22 15:02 DrewciferB

PRs welcomed. Note that the types need to support at minimum wdio 6 and 7, in both sync and async modes, as these are all official versions of WebdriverIO.

As you have experienced, I don't believe this is currently done correctly.

@christian-bromann is best positioned to offer insight on how services that add custom commands can provide accurate types for all WDIO versions that have official support.

Until then, you will probably need to modify the types yourself locally. IIRC there are other issues in this repo that have identified issues with this library and typescript.

tehhowch avatar Feb 09 '22 15:02 tehhowch

@tehhowch I don't feel I really understand this anywhere near well enough to contribute, but making the following change at line 60 of wdio-intercept-service/types/wdio-intercept-service.d.ts removes the problem and allows the project to compile. I tried it in WDIO v6 and v7, in both sync and async mode, and it seems to work. The problem is that I don't understand what's actually going on here, so I don't understand the ramifications of this suggestion (if any):

- type AsyncSync<T> = WebdriverIO.Browser extends WebDriver.Client
+ type AsyncSync<T> = WebdriverIO.Browser extends WebDriver.Capabilities

After making the change, intercept service also seemed to be working normally in all configurations, returning events etc.

DrewciferB avatar Feb 09 '22 17:02 DrewciferB

@tehhowch @christian-bromann any suggestions?

wyhmichael avatar May 25 '22 22:05 wyhmichael

@DrewciferB can confirm, that patching that line works. Should this be fixed?

franklinkim avatar Feb 18 '23 09:02 franklinkim

@franklinkim I recommend upgrading to v8 where this issue should not persist anymore. Feel free to raise a PR with a fix to the v7 branch in webdriverio/webdriverio.

christian-bromann avatar Feb 18 '23 14:02 christian-bromann

@christian-bromann I've upgraded to v8, but it still persists.

TheRealCleany avatar May 15 '23 11:05 TheRealCleany

Yes and it is quite annoying with typescript :/

Grobouls avatar Aug 17 '23 20:08 Grobouls

facing the same issue in wdio v8

derenandrii avatar Sep 06 '23 10:09 derenandrii