-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strongly typing the invoke function #4022
Comments
Hey, thanks for pointing this out! The types definition file that needs to be updated is here: https://github.com/cypress-io/cypress/blob/develop/cli/types/index.d.ts If you'd like to, you can open a pull request with the changes that you think are necessary. |
The code for this is done in cypress-io/cypress#4907, but has yet to be released. |
* add strong return type to 'invoke' command * refactor invoke for clarity. use dtslint tests * add strong args types using typescript 3.0+ features * handle invoke's jquery wrapping of its input * move invoke tests to namespace * add example to jsdocs of 'invoke'
Reverted initial work in 6930cab - we need to handle the case cy.get('.trigger-input-range')
.invoke('val', 25) |
The problem is inside function overloading. Typescript takes only the first function declaration signature. Related issues in typescript repo: |
…io#4907) * add strong return type to 'invoke' command * refactor invoke for clarity. use dtslint tests * add strong args types using typescript 3.0+ features * handle invoke's jquery wrapping of its input * move invoke tests to namespace * add example to jsdocs of 'invoke'
…ypress-io#4907)" This reverts commit 15685db. The type for `invoke` command seems to break jQuery method that take an argument like ```js cy.get('.trigger-input-range') .invoke('val', 25) ```
I understand that this is not the best solution as overloads won't work as expected. With this fix the typings ovf An example I stumbled across today: it.only("asd", () => {
cy.wrap({ fn: () => ({a: 1})})
.invoke("fn")
.its("a")
.should('eq', 1);
}) So I wanted to know if there are any plans to merge this PR again? |
I think this is basically done as of #6667 (I will look again but I think we tackled most of these forms there.) |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
invoke
function is not strongly typed.Desired behavior:
invoke
function is strongly typed.TypeScript has a
ReturnType
type that you can useThe text was updated successfully, but these errors were encountered: