How to define types for Cypress task return type?

Viewed 256

My objective is to define types for my cypress task, written in typescript.

I currently have this when I consume the custom task:

cy.task('customTask').then(v => {
   // v is undefined here - how can I configure types?
});

plugins/index.ts

module.exports = (on) => {
  on('task', {
    customTask: () => {
      return 23;
    }
  });
}
1 Answers
/// <reference types="cypress" />
declare global {
    namespace Cypress {
        interface Chainable {
            task(event: 'customTask'): Chainable<number>;
        }
    }
}
Related