Skip to content

Cypress adds should to every object? #16548

@juanmendes

Description

@juanmendes

I use cypress with the cucumber plugin and noticed that the following TypeScript code which compiles without a problem but crashes at runtime.

const a = 1;
a.should("be.visible");

This is because the following which is downloaded when I npm i cypress: node_modules/cypress/types/chai/index.d.ts:1943

interface Object {
    should: Chai.Assertion;
}

This is causing TypeScript to give me false positives everywhere because I called should() on something that is not a Cypress Chainable but I don't find out about it until runtime.

Augmenting Object's TypeScript definition with an extra method seems like something we did away with since prototype JS taught us how bad it was. Why is it being done? Should I file a bug? It really stinks to have to run a file to be told I have what should be compilation errors.

Originally posted by @juanmendes in #16526

Metadata

Metadata

Assignees

Labels

type: 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