Cypress overwrite ‘type’ command to add a small wait throws promise error if .clear() is called before

Not sure quite why this is occurring. I’d like to add a .wait() before all type commands in my app by overwriting the type command. However I’m running into some issues with the promise quirks of cypress.

Here’s some minimal code to reproduce

<html>
<body>
  <input/> 
</body>
</html>
//someSpec.js
cy.get('input').clear().type(name);
//commands.js
Cypress.Commands.overwrite(
  "type",
  (originalFn, subject, text, options) => {
    cy.wait(0).then(() => originalFn(subject,text,options))
  }
);

This will trigger a cypress error complaining about returning a promise:

Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

  > cy.clear()

The cy command you invoked inside the promise was:

  > cy.wait()

Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.

Cypress will resolve your command with whatever the final Cypress command yields.

The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.

Can anyone please help me get past this hurdle? Thanks!

Related issues: https://github.com/cypress-io/cypress/issues/3166