return type of collection elements cypress

Viewed 42

Hey guys sometimes there few error messages shows up and i am trying to return a collection of elements which i specifying however it complains with the following, so my question is how to get list of elements in cypress and assign sufficient type to it

Type 'Chainable<HTMLAllCollection>' is not assignable to type 'Chainable<JQuery<HTMLAllCollection>>'.
  Types of property 'and' are incompatible.
    Type 'Chainer<HTMLAllCollection>' is not assignable to type 'Chainer<JQuery<HTMLAllCollection>>'.
      Types of parameters 'value' and 'value' are incompatible.
        Type 'JQuery<HTMLAllCollection>' is missing the following properties from type 'HTMLAllCollection': item, namedIte

    static get errorMessages(): Cypress.Chainable<JQuery<HTMLAllCollection>> {
    const arrayOfElements =  cy.get<HTMLAllCollection>('app-error');
    return arrayOfElements;
  }

enter image description here

1 Answers

You're typing is inconsistent - the function is declared to return a Chainable<JQuery<HTMLAllCollection>> but the actual type of the return object is Chainable<HTMLAllCollection>. If you fix this inconsistency, it may resolve your problem.

static get errorMessages(): Cypress.Chainable<JQuery<HTMLAllCollection>> {
    return cy.get<JQuery<HTMLAllCollection>>('app-error');
}
Related