feat: Update types for Cypress.Chainable.task to allow for parameterizing the task return type (#8753)

Co-authored-by: Zach Bloomquist <github@chary.us>
This commit is contained in:
Kevin Wittmer
2020-10-28 11:56:53 -04:00
committed by GitHub
parent 2df18a817f
commit e57c13562d
2 changed files with 13 additions and 1 deletions

View File

@@ -1766,7 +1766,7 @@ declare namespace Cypress {
*
* @see https://on.cypress.io/task
*/
task(event: string, arg?: any, options?: Partial<Loggable & Timeoutable>): Chainable<Subject>
task<S = unknown>(event: string, arg?: any, options?: Partial<Loggable & Timeoutable>): Chainable<S>
/**
* Enables you to work with the subject yielded from the previous command.

View File

@@ -608,3 +608,15 @@ namespace CypressShadowTests {
.get('.foo')
.find('.bar', {includeShadowDom: true})
}
namespace CypressTaskTests {
cy.task<number>('foo') // $ExpectType Chainable<number>
cy.task<number>('foo').then((val) => {
val // $ExpectType number
})
cy.task('foo') // $ExpectType Chainable<unknown>
cy.task('foo').then((val) => {
val // $ExpectType unknown
})
}