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

prevSubject: true Type 'true' is not assignable to type '(boolean | keyof PrevSubjectMap<unknown> | (keyof PrevSubjectMap<unknown>)[]) & (keyof PrevSubjectMap<unknown>)[]' #30672

Closed
agustingutierrezcompass opened this issue Nov 25, 2024 · 2 comments

Comments

@agustingutierrezcompass

Current behavior

Hey Team I have this command:
index.ts

  namespace Cypress {
    interface Chainable {
      hasPseudoElement: (pseudo: string) => Chainable<JQueryWithSelector>;
    }
  }
}

commands.ts

Cypress.Commands.add('hasPseudoElement', {prevSubject: true}, (subject, pseudo) => {
  return window.getComputedStyle(subject[0], pseudo).content !== 'none';
});

And I have this ts error

No overload matches this call.

The last overload gave the following error.
Type 'true' is not assignable to type '(boolean | keyof PrevSubjectMap | (keyof PrevSubjectMap)[]) & (keyof PrevSubjectMap)[]'

Desired behavior

No response

Test code to reproduce

Hey Team I have this command:
index.ts

  namespace Cypress {
    interface Chainable {
      hasPseudoElement: (pseudo: string) => Chainable<JQueryWithSelector>;
    }
  }
}

commands.ts

Cypress.Commands.add('hasPseudoElement', {prevSubject: true}, (subject, pseudo) => {
  return window.getComputedStyle(subject[0], pseudo).content !== 'none';
});

And I have this ts error

No overload matches this call.

The last overload gave the following error.
Type 'true' is not assignable to type '(boolean | keyof PrevSubjectMap | (keyof PrevSubjectMap)[]) & (keyof PrevSubjectMap)[]'

Cypress Version

13.12.0

Node version

18.20.4

Operating System

macOs 14.7.1

Debug Logs

No response

Other

No response

@cacieprins
Copy link
Contributor

Hi @agustingutierrezcompass , it looks like the type declaration for the hasPseudoElement command does not quite match the implementation.

The type declaration only defines one parameter, pseudo: string. However, your implementation is trying to create a command that receives the previous subject. You'll need to make sure your command declaration signature (in index.ts) matches the command implementation signature (in commands.ts), by adding a subject parameter to the type declaration in index.ts. If this still doesn't work for you, feel free to re-open with a reproduction forked from https://github.com/cypress-io/cypress-test-tiny. Thanks!

@agustingutierrezcompass
Copy link
Author

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