Skip to content

Incorrect typing of browser.execute() (InnerArguments) for elements #6486

@leoselig

Description

@leoselig

Environment:

  • WebdriverIO version: 7.0.5
  • Mode: WDIO Testrunner
  • If WDIO Testrunner, running sync/async: async
  • Node.js version: 15.6.0
  • NPM version: 7.4.0
  • Browser name and version: not applicable
  • Platform name and version: not applicable
  • Additional wdio packages used (if applicable): not applicable

Config of WebdriverIO
not applicable

Describe the bug
In version 7 of WDIO, the type definitions for browser.execute() seem to have changed but have become incorrect when using WebdriverIO.Elements as arguments. The type definitions do not model the conversion of WebdriverIO.Elements into W3C DOM Elements. Instead, inner arguments types are expected to also be the outer ones.

To Reproduce

  1. Setup WebdriverIO project with TypeScript as described here:
  2. Put this code into any file:
function foo(wdioElement: WebdriverIO.Element) {
  await browser.execute((domElement: Element) => {
    domElement.addEventListener("click", () => console.log("whatever"));
  }, wdioElement);
}
  1. Run TypeScript to check for errors

Expected behavior
TS should not show errors since at runtime WebdriverIO.Element is landing in the browser-side as a DOM Element. Note, that stripping the Element type from domElement: Element will move the error to the domElement.addEventListener(...) line.

Log

system-tests/src/safariClickHack.ts:35:8 - error TS2345: Argument of type 'WebdriverIO.Element' is not assignable to parameter of type 'Element'.
  Type 'Element' is missing the following properties from type 'Element': assignedSlot, attributes, classList, className, and 120 more.

35     }, element);
          ~~~~~~~

Additional context
Used TypeScript version 4.1.5.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛TypeScriptgood first picka reasonable task to start getting familiar with the code basehelp wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions