For anyone who finds this and still looking for help, based on the above and following this documentation from Cypress and had to customize it a bit for Task
https://docs.cypress.io/app/tooling/typescript-support#Types-for-Custom-Commands
Ended up with a cypress.d.ts
file in my root with the following to dynamically set response types for the specific custom task name and not override all of "task".
declare global {
namespace Cypress {
interface Chainable {
task<E extends string>(
event: E,
...args: any[]
): Chainable<
E extends 'customTaskName'
? CustomResponse
: // add more event types here as needed
unknown
>
}
}
}
Probably a chance for a cleaner approach if you have a large number of custom tasks, maybe a value map or something of the like. For now i am moving on cause way too much time wasted on this.