Skip to content

Commit

Permalink
feat: infer argument types in command implementations (#17496)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com>
Co-authored-by: Chris Breiding <chrisbreiding@gmail.com>
  • Loading branch information
3 people committed Aug 10, 2021
1 parent b01f8f8 commit bfa8347
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 4 additions & 4 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ declare namespace Cypress {
* Currently executing test runnable instance.
*/
currentTest: {
title: string,
title: string
titlePath: string[]
}

Expand Down Expand Up @@ -402,9 +402,9 @@ declare namespace Cypress {
* @see https://on.cypress.io/api/commands
*/
Commands: {
add(name: string, fn: (...args: any[]) => CanReturnChainable): void
add(name: string, options: CommandOptions, fn: (...args: any[]) => CanReturnChainable): void
overwrite(name: string, fn: (...args: any[]) => CanReturnChainable): void
add<T extends keyof Chainable>(name: T, fn: Chainable[T]): void
add<T extends keyof Chainable>(name: T, options: CommandOptions, fn: Chainable[T]): void
overwrite<T extends keyof Chainable>(name: T, fn: Chainable[T]): void
}

/**
Expand Down
22 changes: 18 additions & 4 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,31 @@ namespace CypressIsCyTests {
})
}

declare namespace Cypress {
interface Chainable {
newCommand: (arg: string) => void
}
}

namespace CypressCommandsTests {
Cypress.Commands.add('newCommand', () => {
Cypress.Commands.add('newCommand', (arg) => {
// $ExpectType string
arg
return
})
Cypress.Commands.add('newCommand', { prevSubject: true }, () => {
Cypress.Commands.add('newCommand', { prevSubject: true }, (arg) => {
// $ExpectType string
arg
return
})
Cypress.Commands.add('newCommand', () => {
Cypress.Commands.add('newCommand', (arg) => {
// $ExpectType string
arg
return new Promise((resolve) => {})
})
Cypress.Commands.overwrite('newCommand', () => {
Cypress.Commands.overwrite('newCommand', (arg) => {
// $ExpectType string
arg
return
})
}
Expand Down

0 comments on commit bfa8347

Please sign in to comment.