cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.1k stars 3.19k forks source link

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

Closed agustingutierrezcompass closed 7 hours ago

agustingutierrezcompass commented 9 hours ago

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 commented 7 hours ago

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 commented 4 hours ago

https://github.com/cypress-io/cypress-test-tiny/pull/96/files here is an example @cacieprins