'How to define types for Cypress task return type?

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;
    }
  });
}


Solution 1:[1]

/// <reference types="cypress" />
declare global {
    namespace Cypress {
        interface Chainable {
            task(event: 'customTask'): Chainable<number>;
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1