webdriverio-community / wdio-intercept-service

🕸 Capture and assert HTTP ajax calls in webdriver.io
MIT License
104 stars 33 forks source link

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

Open DrewciferB opened 2 years ago

DrewciferB commented 2 years ago

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 👍

tehhowch commented 2 years ago

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.

DrewciferB commented 2 years ago

@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.

wyhmichael commented 2 years ago

@tehhowch @christian-bromann any suggestions?

franklinkim commented 1 year ago

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

christian-bromann commented 1 year ago

@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.

TheRealCleany commented 1 year ago

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

Grobouls commented 1 year ago

Yes and it is quite annoying with typescript :/

derenandrii commented 12 months ago

facing the same issue in wdio v8