Skip to content

Commit 65d1d60

Browse files
fix: typescript compilation when checking libs
When the skipLibCheck Typescript compiler option is set to false compilation fails. This is due to the global WebdriverIO.Element interface being extended with ElementBase: the compiler complains that the types of $, execute and executeAsync are not identical to those found in the webdriverio package. To fix the compilation the WebdriverIO.Element interface either needs to be extended with identical types as those used in the webdriverio package or we stop extending it with ElementBase entirely. The first option is not realistic as at build time we don't know which version of the webdriverio package the end user will have installed. We can however stop extendng the interface: WebdriverIO.Element is only extended with ElementBase to allow an element to be passed to the within method internally, if instead we coerce the WebdriverIO.Element to be an ElementBase we no longer need to extend the interface. This does not cause any loss in type safety either as we were effectively coercing the type to be the same as ElementBase when we extended the WebdriverIO.Element interface anyways. Change the test tsconfigs to have skipLibCheck set to false so that the typecheck script catches these types of bugs in future.
1 parent 4c0d55c commit 65d1d60

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function setupBrowser(browser: BrowserBase): WebdriverIOQueries {
246246
...args: Parameters<WebdriverIOQueries[QueryName]>
247247
) => {
248248
const body = await browser.$('body')
249-
return within(body)[queryName](...(args as any[]))
249+
return within(body as ElementBase)[queryName](...(args as any[]))
250250
}
251251

252252
// add query to response queries

src/wdio-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ eslint-disable @typescript-eslint/no-explicit-any,
1111

1212
declare global {
1313
namespace WebdriverIO {
14-
interface Element extends ElementBase {}
14+
interface Element {}
1515
}
1616
}
1717

test/async/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"types": ["node", "jest", "webdriverio/async", "@wdio/mocha-framework"],
5-
"baseUrl": "."
4+
"types": ["node", "webdriverio/async", "@wdio/mocha-framework", "expect-webdriverio"],
5+
"baseUrl": ".",
6+
"skipLibCheck": false
67
},
78
"exclude": [],
89
"include": ["**/*.ts"]

test/sync/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"types": ["node", "jest", "webdriverio/sync", "@wdio/mocha-framework"]
4+
"types": ["node", "webdriverio/sync", "@wdio/mocha-framework", "expect-webdriverio"],
5+
"skipLibCheck": false
56
},
67
"exclude": [],
78
"include": ["**/*.ts"]

0 commit comments

Comments
 (0)