-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Typings for Command.add are missing types for the subject #18879
Comments
For me "confirmClick" is not. Neither add nor overwrite is working at the moment. |
I have done some attempts at fixing this for |
My current workaround for this locally is to use a wrapper function as below and change - Cypress.Commands.add('confirmClick', { prevSubject: true }, (confirmButton) => {
+ addCypressCommand('confirmClick', { prevSubject: true }, (confirmButton) => { type AddSubjectArgument<
TPrevSubject extends Cypress.CommandOptions['prevSubject'],
TFunction extends (...args: any) => any
> = (
...args: [
TPrevSubject extends true
? JQuery | HTMLElement
: undefined | JQuery | HTMLElement,
...Parameters<TFunction>
]
) => ReturnType<TFunction>;
function addCypressCommand<
T extends keyof Cypress.Chainable,
TOptions extends Cypress.CommandOptions
>(
name: T,
options: TOptions,
fn: Cypress.Chainable[T] extends (...args: any) => any
? TOptions['prevSubject'] extends false
? Cypress.Chainable[T]
: AddSubjectArgument<TOptions['prevSubject'], Cypress.Chainable[T]>
: never
): void {
Cypress.Commands.add<T>(name, options, fn as Cypress.Chainable[T]);
} |
EDIT: I was proposing a solution, but I spoke too soon and later found out that it actually doesn't work, so I'm removing it to prevent confusion |
My workaround does handle all values of prevSubject, just in 2 places rather than one. fn: Cypress.Chainable[T] extends (...args: any) => any
? TOptions['prevSubject'] extends false
? Cypress.Chainable[T]
: AddSubjectArgument<TOptions['prevSubject'], Cypress.Chainable[T]>
: never At this place we check if prevSubject is false, which means that the subject should not be added - hence returning Key is this part of the type at this point, our type of TPrevSubject is ...args: [
TPrevSubject extends true
? JQuery | HTMLElement
: undefined | JQuery | HTMLElement,
...Parameters<TFunction> This is the solution I used in the attached PR which passes all the TS 4 tests, the only problem I have is that this only seems to work in TS 4 so the TS 3 tests fail. |
We have the same problem, typings are not available for child commands since #17496 was introduced. |
Bump |
Same issue here. All my commands already have typescript declaration, but now it breaks because the prevSubject parameter isn't present in the declaration (and it shouldn't be, since it's not directly provided by the user) |
This will now be resolved in #19003 |
The code for this is done in cypress-io/cypress#19003, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
A simple custom command that relies on prevSubject is not correctly typed.
Desired behavior
The "previous subject" argument should be correctly added to the command type and error if not passed.
Test code to reproduce
Cypress Version
9.0.0
Other
No response
The text was updated successfully, but these errors were encountered: