Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: infer argument types in command implementations #17496

Merged
merged 4 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
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 Cypress.Chainable>(name: T, fn: Cypress.Chainable[T]): void
add<T extends keyof Cypress.Chainable>(name: T, options: CommandOptions, fn: Cypress.Chainable[T]): void
overwrite<T extends keyof Cypress.Chainable>(name: T, fn: Cypress.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