Skip to content

ChainablePromiseElement and ChainablePromiseArray wrongly resolved to any #1871

@dprevost-LMI

Description

@dprevost-LMI

ChainablePromiseElement and ChainablePromiseArray are not resolved correctly because of the provided generics. IDE shows them defined as any.

Image

Once generics are removed, it is no longer any and the tsc command unfolds typing issues

Image
src/matchers/element/toHaveAttribute.ts:59:56 - error TS2345: Argument of type 'Element | ChainablePromiseElement' is not assignable to parameter of type 'Element | ElementArray'.
  Type 'ChainablePromiseElement' is not assignable to type 'Element | ElementArray'.
    Type 'ChainablePromiseElement' is not assignable to type 'Element'.
      Types of property 'parent' are incompatible.
        Type 'Promise<Element | Browser | MultiRemoteBrowser>' is not assignable to type 'Element | Browser'.

59         const result = await executeCommand.call(this, el, conditionAttr, {}, [attribute])
                                                          ~~

src/matchers/element/toHaveAttribute.ts:65:34 - error TS2345: Argument of type 'Element | ChainablePromiseElement' is not assignable to parameter of type 'string | Element | ElementArray'.
  Type 'ChainablePromiseElement' is not assignable to type 'string | Element | ElementArray'.
    Type 'ChainablePromiseElement' is not assignable to type 'Element'.
      Types of property 'parent' are incompatible.
        Type 'Promise<Element | Browser | MultiRemoteBrowser>' is not assignable to type 'Element | Browser'.

65     const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {})
                                    ~~

src/matchers/element/toHaveAttribute.ts:87:52 - error TS2345: Argument of type 'WdioElementMaybePromise' is not assignable to parameter of type 'ChainablePromiseElement'.
  Type 'Element' is not assignable to type 'ChainablePromiseElement'.
    Types of property 'elementId' are incompatible.
      Type 'string' is not assignable to type 'Promise<string>'.

87         ? await toHaveAttributeAndValue.call(this, received, attribute, value, options)
                                                      ~~~~~~~~

src/matchers/element/toHaveClass.ts:87:47 - error TS2345: Argument of type 'Element' is not assignable to parameter of type 'ChainablePromiseElement'.
  Types of property 'elementId' are incompatible.
    Type 'string' is not assignable to type 'Promise<string>'.

87     return toHaveAttributeAndValue.call(this, el, 'class', className, {
                                                 ~~

src/matchers/element/toHaveHref.ts:16:61 - error TS2345: Argument of type 'WdioElementMaybePromise' is not assignable to parameter of type 'ChainablePromiseElement'.
  Type 'Element' is not assignable to type 'ChainablePromiseElement'.
    Types of property 'elementId' are incompatible.
      Type 'string' is not assignable to type 'Promise<string>'.

16     const result = await toHaveAttributeAndValue.call(this, el, 'href', expectedValue, options)
                                                               ~~

src/matchers/element/toHaveId.ts:16:96 - error TS2345: Argument of type 'WdioElementMaybePromise' is not assignable to parameter of type 'ChainablePromiseElement'.
  Type 'Element' is not assignable to type 'ChainablePromiseElement'.
    Types of property 'elementId' are incompatible.
      Type 'string' is not assignable to type 'Promise<string>'.

16     const result: ExpectWebdriverIO.AssertionResult = await toHaveAttributeAndValue.call(this, el, 'id', expectedValue, options)
                                                                                                  ~~
Found 6 errors.

Fixing them...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions