From e57c13562dfadda2ed2d7e7709edac5dda0189d1 Mon Sep 17 00:00:00 2001 From: Kevin Wittmer Date: Wed, 28 Oct 2020 11:56:53 -0400 Subject: [PATCH] feat: Update types for Cypress.Chainable.task to allow for parameterizing the task return type (#8753) Co-authored-by: Zach Bloomquist --- cli/types/cypress.d.ts | 2 +- cli/types/tests/cypress-tests.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 018e7b4b8d..0a0c696ded 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -1766,7 +1766,7 @@ declare namespace Cypress { * * @see https://on.cypress.io/task */ - task(event: string, arg?: any, options?: Partial): Chainable + task(event: string, arg?: any, options?: Partial): Chainable /** * Enables you to work with the subject yielded from the previous command. diff --git a/cli/types/tests/cypress-tests.ts b/cli/types/tests/cypress-tests.ts index 05625406d9..32a6dad7f4 100644 --- a/cli/types/tests/cypress-tests.ts +++ b/cli/types/tests/cypress-tests.ts @@ -608,3 +608,15 @@ namespace CypressShadowTests { .get('.foo') .find('.bar', {includeShadowDom: true}) } + +namespace CypressTaskTests { + cy.task('foo') // $ExpectType Chainable + cy.task('foo').then((val) => { + val // $ExpectType number + }) + + cy.task('foo') // $ExpectType Chainable + cy.task('foo').then((val) => { + val // $ExpectType unknown + }) +}