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

refactor typedefs for cy #3499

Merged
merged 16 commits into from
Jul 15, 2019
4 changes: 3 additions & 1 deletion cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4237,6 +4237,8 @@ declare namespace Cypress {
// Diff taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766
type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T]
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>

interface cy extends Chainable<undefined> {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this interface cy be documented please?

}

/**
Expand All @@ -4248,7 +4250,7 @@ cy.get('button').click()
cy.get('.result').contains('Expected text')
```
*/
declare const cy: Cypress.Chainable<undefined>
declare const cy: Cypress.cy
/**
* Global variable `Cypress` holds common utilities and constants.
* @see https://on.cypress.io/api
Expand Down
27 changes: 27 additions & 0 deletions cli/types/tests/plugins-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Test that plugin authors can write .d.ts files to extend Cypress types
* Unfortunately we cannot test that vendor types located in node_modules are working
* since those are copied as part of the deploy process
*
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs more documentation - this is what someone who writes a new command or adds a property to cy global object should do right. So we should describe this better, even for ourselves.

Also, the formatting is all off below, maybe it needs a prettier ...


declare namespace Cypress {
interface cy {
cyProp: number
}
interface Chainable {
chainerProp: number
}
}

// $ExpectType number
cy.cyProp

// $ExpectError
cy.get('.element').cyProp

// $ExpectType number
cy.chainerProp

// $ExpectType number
cy.get('.element').chainerProp