1

I spotted that when I'm using while loop, cypress does not work, so instead of while loop I found this kind of solution:

const functionName = () => {
  if ( a != b ) {
    this.functionName();
  } else {
    cy.get(".selector").click()
  }
};

This block of code (typescript) works really well, but 'this' is highlighted in red and the message appears: "Object is possibly 'undefined'."

Any idea how can I to get rid off this error?

Mag
  • 207
  • 1
  • 8

1 Answers1

1

Assuming it's a typescript error, add the Non-null assertion operator

// Compiled with --strictNullChecks
function validateEntity(e?: Entity) {
  // Throw exception if e is null or invalid entity
}
function processEntity(e?: Entity) {
  validateEntity(e);
  let s = e!.name; // Assert that e is non-null and access name
}

For reference, How to suppress "error TS2533: Object is possibly 'null' or 'undefined'" answers the same question.

You probably don't need the this. prefix at all, since the function is defined on the current scope (not a class method).

Udo.Kier
  • 228
  • 7