'How to declare types for Cypress tasks with minimal duplication?

I define a function

function a(arg: X): Y { ... }

...
on('task', { a })

for use as a Cypress task, and can add types:

declare global {
  namespace Cypress {
    interface Chainable {
      task(event: 'a', arg: Parameters<typeof a>[0]): Chainable<ReturnType<typeof a>>;
    }
  }
}

Repeat for each task (omitting arg where necessary). Is there a way to decrease repetition? Of course, I could write ... arg: X): Chainable<Y>, but then they could go out of sync with a's definition and the compiler wouldn't catch it.



Sources

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

Source: Stack Overflow

Solution Source