Skip to content

Cypress Document function typing is incorrect #17695

@JordanMcDonough

Description

@JordanMcDonough

Current behavior

The cy.document function has the wrong typings for typescript.
In the docs it specifies timeout as a valid property, however it only has the log option specified.
https://docs.cypress.io/api/commands/document#Usage

image

Desired behavior

The type file should specify it to be timeoutable:

    /**
     * Get the window.document of the page that is currently active.
     *
     * @see https://on.cypress.io/document
     * @example
     *    cy.document()
     *      .its('contentType')
     *      .should('eq', 'text/html')
     */
    document(options?: Partial<Loggable & Timeoutable): Chainable<Document>

Test code to reproduce

describe('a test', () => {
    it('should have the right typing', () => {
        // The below should not throw a type error
        cy.document({ timeout: 5000 }).should('exist');
    });
});

Cypress Version

8.0.0

Other

Temporary workaround:

Create the following file: ./src/@types/cypress.d.ts
With the content:

declare namespace Cypress {
    interface Chainable {
        document(options?: Partial<Loggable & Timeoutable>): Chainable<Document>
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerstype: typingsIssue related to Cypress types (for TypeScript)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions