-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
prevSubject: 'element' is disallowed by current types #24416
prevSubject: 'element' is disallowed by current types #24416
Comments
This is the closest I could get to the code in the guide while making TypeScript happy: // cypress/support/index.d.ts
typeRandomWords(count?: number, options?: Partial<TypeOptions>): Chainable<JQuery<HTMLElement>>
// cypress/support/commands.ts
Cypress.Commands.add(
'typeRandomWords',
{ prevSubject: ['element'] },
(subject /* :JQuery<HTMLElement> */, count = 3, options?) => {
return cy.wrap(subject).type(generateRandomWords(count), options)
}
) |
@jamesarosen Thank you for opening this issue as well as providing a work around to this issue. I have been able to replicate this on my end and will be investigating this further. |
According to the internal interface This makes TS happy: declare global {
namespace Cypress {
interface Chainable {
typeRandomWords(count?: number, options?: Partial<TypeOptions>): Chainable<JQueryWithSelector>;
}
}
}
Cypress.Commands.add('typeRandomWords', { prevSubject: 'element' }, (subject, count = 3, options?) => {
return cy.wrap(subject).type(generateRandomWords(count), options);
}); The types look ok, but the docs need to be updated with the correct return type. |
@A-Shleifman would you be interested in contributing the updates? |
Current behavior
The TypeScript guide gives this example:
That gives the following TypeScript error:
The available types for
add
areOf those, every use of
CommandOptions
includes the&
intersection operator to further limitprevSubject
and none of them allows'element'
.Desired behavior
Either (a)
'element'
is an allowedprevSubject
or the guide reflects the correct usage.Test code to reproduce
See https://docs.cypress.io/guides/tooling/typescript-support#Types-for-Custom-Commands
Cypress Version
10.9.0
Node version
v16.17.1
Operating System
macOS 12.6
Debug Logs
Other
Related: #18940, #20377, #21106
The text was updated successfully, but these errors were encountered: