Skip to content
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

Type error when trying to chain drag(...).then(...) #126

Open
p1xell0rd opened this issue Dec 5, 2022 · 1 comment
Open

Type error when trying to chain drag(...).then(...) #126

p1xell0rd opened this issue Dec 5, 2022 · 1 comment

Comments

@p1xell0rd
Copy link

p1xell0rd commented Dec 5, 2022

I'm trying to chain the then method after calling drag like this:

cy.get(`[data-itemId="${itemId}"]`)
  .drag(`[data-draggableId="${targetDraggableId}"]`)
  .then((success: boolean) => assert.isTrue(success));

That's pretty much what is also shown in the readme file, but I get the Typescript error TS2339: Property 'then' does not exist on type 'true'.
Looking at the type declarations for the drag function, I think it either has to return Chainable or a Promise instead of a boolean in order to allow for chaining, or am I missing something?

@Xvezda
Copy link

Xvezda commented Apr 28, 2023

I added the following code to support/commands to make this work:

declare global {
  namespace Cypress {
    interface Chainable {
      drag<K extends keyof HTMLElementTagNameMap>(targetSelector: K, options?: Options): Chainable<(success: boolean) => unknown>;
      drag<E extends Node = HTMLElement>(targetSelector: string, options?: Options): Chainable<(success: boolean) => unknown>;
      drag(targetAlias: string, options?: Options): Chainable<(success: boolean) => unknown>;
    }
  }
}

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

No branches or pull requests

2 participants