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

Property 'state' does not exist on type 'Chainable<undefined>' #4771

Closed
lifeiscontent opened this issue Jul 21, 2019 · 6 comments
Closed

Property 'state' does not exist on type 'Chainable<undefined>' #4771

lifeiscontent opened this issue Jul 21, 2019 · 6 comments
Labels
stage: ready for work The issue is reproducible and in scope type: typings Issue related to Cypress types (for TypeScript)

Comments

@lifeiscontent
Copy link

lifeiscontent commented Jul 21, 2019

Current behavior:

cy.state doesn't exist on typescript definitions

Desired behavior:

cy.state exists on typescript definitions

Steps to reproduce: (app code and test code)

just check cy.state and see its not defined

Versions

Cypress Latest

@jennifer-shehane jennifer-shehane added topic: typescript stage: ready for work The issue is reproducible and in scope labels Jul 23, 2019
@jennifer-shehane
Copy link
Member

Previous docs issue for cy.state cypress-io/cypress-documentation#108

@amitguptagwl
Copy link

Property 'state' does not exist on type 'cy'.

/// <reference types="cypress" />
// @ts-check
exports.HomePage = () => {
    return cy.state("currentPage");
}

@jennifer-shehane jennifer-shehane added type: typings Issue related to Cypress types (for TypeScript) and removed topic: typescript labels Mar 3, 2020
@sainthkh
Copy link
Contributor

We can define it like below:

interface State {
  (property: 'document'): Document
  (property: 'window'): Cypress.AUTWindow
  (property: 'runnable'): any
  // etc. etc.
  (property: string): any
}

But the problem is that it's not sure cy.state should be revealed or not. => Related link

@ShaneHudson
Copy link

For anyone that is trying to use @sainthkh's answer, use it like this:

  interface cy {
    state: State;
  }

@kdp88
Copy link

kdp88 commented Sep 9, 2022

@ShaneHudson where would I put this interface, currently I have it in the index.d.ts but my spec file still gives ts error, im thinking i gotta add it to commands.ts?

@Keysox
Copy link

Keysox commented Nov 22, 2022

We're using:

declare global {
  namespace Cypress {
    interface Chainable {
      state(state: any): any
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: ready for work The issue is reproducible and in scope type: typings Issue related to Cypress types (for TypeScript)
Projects
None yet
Development

No branches or pull requests

7 participants