Skip to content

fix: handle unknown return type from getValue() in webdriverio 9.24.0#1435

Open
elaichenkov wants to merge 1 commit intomainfrom
fix/getValue-unknown-type
Open

fix: handle unknown return type from getValue() in webdriverio 9.24.0#1435
elaichenkov wants to merge 1 commit intomainfrom
fix/getValue-unknown-type

Conversation

@elaichenkov
Copy link
Copy Markdown
Member

Problem

The dependabot PR #1431 (bumping webdriverio from 9.23.2 to 9.24.0) fails to build with:

src/element/textToBePresentInElementValue.ts(25,16): error TS18046: 'value' is of type 'unknown'

In webdriverio 9.24.0, element.getValue() return type changed from Promise<string> to Promise<unknown> because it delegates to getElementProperty() (for W3C) which can return any JS type.

Solution

Use a typeof guard instead of a type assertion:

return typeof value === 'string' && value.includes(expectedValue)

getValue() now returns Promise<unknown> instead of Promise<string>.
Use typeof guard instead of type assertion to safely handle non-string
return values (e.g. null), returning false when value is not a string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant