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

Typescript error while using Cypress.Command.add(): Property 'selector' does not exist on type 'JQuery<HTMLElement>' #20376

Closed
atarek12 opened this issue Feb 27, 2022 · 1 comment · Fixed by #20377 or #21106

Comments

@atarek12
Copy link
Contributor

Current behavior

I am getting a Typescript error for those cases:

  • Cypress.Command.add() with { prevSubject: true }
Cypress.Commands.add("newCommand", { prevSubject: true }, (element) => {});

In the above example, element is of type unknown but instead, it should be JQuery<HTMLElement>, this could be handled by passing the generics values like that:

Cypress.Commands.add<"newCommand","element">("newCommand", { prevSubject: true }, (element) => {});

But I think passing true to the prevSubject option, the element type should be JQuery<HTMLElement> by itself.

  • Cypress.Command.add() with {prevSubject: "element" }
Cypress.Commands.add("newCommand", { prevSubject: "element" }, (element) => {
  element.selector
});

I am trying to access the selector property, but I got a typescript error that it does not exist on type JQuery<HTMLElement>

Desired behavior

No typescript error should be printed, as the selector property does exist in the element object.

Test code to reproduce

https://github.com/atarek12/cypress/blob/fix-prevSubject-types/cli/types/tests/cypress-tests.ts#L87

Cypress Version

9.5.0

Other

No response

@cypress-bot cypress-bot bot added the stage: needs review The PR code is done & tested, needs review label Feb 27, 2022
atarek12 added a commit to atarek12/cypress that referenced this issue Feb 27, 2022
atarek12 added a commit to atarek12/cypress that referenced this issue Feb 27, 2022
atarek12 added a commit to atarek12/cypress that referenced this issue Feb 27, 2022
@cypress-bot cypress-bot bot added stage: waiting stage: needs review The PR code is done & tested, needs review and removed stage: needs review The PR code is done & tested, needs review stage: waiting labels Apr 8, 2022
flotwig pushed a commit that referenced this issue Apr 15, 2022
Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
flotwig added a commit that referenced this issue Apr 15, 2022
@flotwig flotwig reopened this Apr 15, 2022
tbiethman added a commit that referenced this issue Apr 15, 2022
@atarek12 atarek12 mentioned this issue Apr 15, 2022
5 tasks
tgriesser added a commit that referenced this issue Apr 20, 2022
…e-config

* 10.0-release:
  chore: Move component-index generation to scaffold-config package (#21090)
  fix: label text should be clickable to toggle snapshot highlight (#21122)
  feat: add next preset to webpack-dev-server-fresh (#21069)
  chore: add dev-servers as deps to server to be included in the binary (#21142)
  fix: do not highlight preExtension if selected option is renameFolder (#21121)
  fix(unify): Remove 'Reconfigure' dropdown from Testing Type chooser (#21063)
  feat(unify): launchpad header breadcrumbs and reusable tooltip component (#20648)
  test: add windows-test-kitchensink job (#20847)
  fix: aut centering and height calculation (#21019)
  chore: fix tests that fail on windows (#21055)
  fix: running a new test after already having run tests (#21087)
  fix: ct project setup framework keys for next and nuxt (#21116)
  fix: remove MountReturn from scaffolded ct support file (#21119)
  fix: do not scaffold fixtures if folder exist (#21078)
  fix: revert "fix: types for Cypress.Commands.add (#20376)" (#21104)
  chore: Update Chrome (stable) to 100.0.4896.127 and Chrome (beta) to 101.0.4951.34 (#21083)
  fix: types for Cypress.Commands.add (#20376) (#20377)
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 25, 2022

Released in 9.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.6.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Apr 25, 2022
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Apr 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants