Skip to content

Commit 20e9832

Browse files
committed
chore: Remove ChainableArray interface
1 parent 48ea890 commit 20e9832

File tree

2 files changed

+38
-68
lines changed

2 files changed

+38
-68
lines changed

cli/types/index.d.ts

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ declare namespace Cypress {
339339
* @see https://on.cypress.io/each
340340
*/
341341
each<E extends Node = HTMLElement>(fn: (element: JQuery<E>, index: number, $list: E[]) => void): Chainable<JQuery<E>> // Can't properly infer type without breaking down Chainable
342+
each(fn: (item: any, index: number, $list: any[]) => void): Chainable<Subject>
342343

343344
/**
344345
* End a chain of commands
@@ -425,7 +426,7 @@ declare namespace Cypress {
425426
*
426427
* @see https://on.cypress.io/getcookies
427428
*/
428-
getCookies(options?: Partial<Loggable & Timeoutable>): ChainableArray<Cookie>
429+
getCookies(options?: Partial<Loggable & Timeoutable>): Chainable<Cookie[]>
429430

430431
/**
431432
* Navigate back or forward to the previous or next URL in the browser’s history.
@@ -711,13 +712,15 @@ declare namespace Cypress {
711712
*/
712713
submit(options?: Partial<Loggable & Timeoutable>): Chainable<Subject>
713714

715+
spread<S extends object | any[] | string | number | boolean>(fn: (...args: any[]) => S): Chainable<S>
716+
spread(fn: (...args: any[]) => void): Chainable<Subject>
717+
714718
/**
715719
* Enables you to work with the subject yielded from the previous command.
716720
*
717721
* @see https://on.cypress.io/then
718722
*/
719-
then<S extends any[]>(fn: (this: ObjectLike, currentSubject: Subject) => S, options?: Partial<Timeoutable>): ChainableArray<S>
720-
then<S extends object | string | number | boolean>(fn: (this: ObjectLike, currentSubject: Subject) => S, options?: Partial<Timeoutable>): Chainable<S>
723+
then<S extends object | any[] | string | number | boolean>(fn: (this: ObjectLike, currentSubject: Subject) => S, options?: Partial<Timeoutable>): Chainable<S>
721724
then(fn: (this: ObjectLike, currentSubject: Subject) => void, options?: Partial<Timeoutable>): Chainable<Subject>
722725

723726
/**
@@ -804,7 +807,7 @@ declare namespace Cypress {
804807
*/
805808
wait(ms: number, options?: Partial<Loggable & Timeoutable>): Chainable<undefined>
806809
wait(alias: string, options?: Partial<Loggable & Timeoutable>): Chainable<WaitXHR>
807-
wait(alias: string[], options?: Partial<Loggable & Timeoutable>): ChainableArray<WaitXHR>
810+
wait(alias: string[], options?: Partial<Loggable & Timeoutable>): Chainable<WaitXHR[]>
808811

809812
/**
810813
* Get the window object of the page that is currently active.
@@ -834,7 +837,6 @@ declare namespace Cypress {
834837
* @see https://on.cypress.io/wrap
835838
*/
836839
wrap<E extends Node = HTMLElement>(element: E | JQuery<E>, options?: Partial<Loggable & Timeoutable>): Chainable<JQuery<E>>
837-
wrap<S>(objects: S[], options?: Partial<Loggable & Timeoutable>): ChainableArray<S>
838840
wrap<S>(object: S, options?: Partial<Loggable & Timeoutable>): Chainable<S>
839841

840842
/**
@@ -846,59 +848,6 @@ declare namespace Cypress {
846848
writeFile<C extends FileContents>(filePath: string, contents: C, encoding: Encodings, options?: Partial<Loggable>): Chainable<C>
847849
}
848850

849-
/**
850-
* Chainable interface with stronger typing for array subjects
851-
*/
852-
interface ChainableArray<Subject> extends Omit<Chainable<Subject[]>, 'and' | 'as' | 'each' | 'should' | 'then'> {
853-
/**
854-
* Create an assertion. Assertions are automatically retried until they pass or time out.
855-
*
856-
* @alias should
857-
* @see https://on.cypress.io/and
858-
*/
859-
and: ChainerArray<Subject>
860-
861-
/**
862-
* Assign an alias for later use. Reference the alias later within a
863-
* [cy.get()](https://on.cypress.io/get) or
864-
* [cy.wait()](https://on.cypress.io/wait) command with a `@` prefix.
865-
*
866-
* @see https://on.cypress.io/as
867-
*/
868-
as(alias: string): ChainableArray<Subject>
869-
870-
/**
871-
* Iterate through an array like structure (arrays or objects with a length property).
872-
* @see https://on.cypress.io/api/each
873-
*/
874-
each<S extends Subject>(fn: (element: S, index: number, $list: Subject[]) => void): ChainableArray<S>
875-
876-
/**
877-
* Expand an array into multiple arguments.
878-
* Identical to `.then()`, but always expects an array-like structure as its subject.
879-
*
880-
* @see https://on.cypress.io/spread
881-
*/
882-
spread<S extends object | string | number | boolean>(fn: (...args: Subject[]) => S): Chainable<S>
883-
spread(fn: (...args: Subject[]) => void): ChainableArray<Subject>
884-
885-
/**
886-
* Create an assertion. Assertions are automatically retried until they pass or time out.
887-
*
888-
* @see https://on.cypress.io/should
889-
*/
890-
should: ChainerArray<Subject>
891-
892-
/**
893-
* Enables you to work with the subject yielded from the previous command.
894-
*
895-
* @see https://on.cypress.io/then
896-
*/
897-
then<S extends any[]>(fn: (this: ObjectLike, currentSubject: Subject[]) => S, options?: Partial<Timeoutable>): ChainableArray<S>
898-
then<S extends object | string | number | boolean>(fn: (this: ObjectLike, currentSubject: Subject[]) => S, options?: Partial<Timeoutable>): Chainable<S>
899-
then(fn: (this: ObjectLike, currentSubject: Subject[]) => void, options?: Partial<Timeoutable>): ChainableArray<Subject>
900-
}
901-
902851
interface CookieDefaults {
903852
whitelist: string | string[] | RegExp | ((cookie: any) => boolean)
904853
}
@@ -1281,12 +1230,6 @@ declare namespace Cypress {
12811230
(fn: (currentSubject: Subject) => void): Chainable<Subject>
12821231
}
12831232

1284-
interface ChainerArray<Subject> {
1285-
(chainers: string, value?: any): ChainableArray<Subject>
1286-
(chainers: string, method: string, value: any): ChainableArray<Subject>
1287-
(fn: (currentSubject: Subject[]) => void): ChainableArray<Subject>
1288-
}
1289-
12901233
/**
12911234
* The clock starts at the unix epoch (timestamp of 0). This means that when you instantiate new Date in your application, it will have a time of January 1st, 1970.
12921235
*/

cli/types/tests/cypress-tests.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ namespace CypressLogsTest {
5858
})
5959
}
6060

61+
cy.wrap({ foo: [1, 2, 3] })
62+
.its('foo')
63+
.each((s: number) => {
64+
s
65+
})
66+
67+
cy.wrap({ foo: ['bar', 'baz'] })
68+
.its('foo')
69+
.then(([first, second]) => {
70+
first // $ExpectType string
71+
})
72+
.spread((first: string, second: string) => {
73+
first // $ExpectType string
74+
// return first as string
75+
})
76+
.each((s: string) => {
77+
s // $ExpectType string
78+
})
79+
.then(s => {
80+
s // $ExpectType string[]
81+
})
82+
83+
cy.wrap(['bar', 'baz'])
84+
.spread((first, second) => {
85+
first // $ExpectType any
86+
})
87+
6188
cy.wrap({ foo: 'bar' })
6289
.then(s => {
6390
s // $ExpectType { foo: string; }
@@ -72,28 +99,28 @@ cy.wrap({ foo: 'bar' })
7299
})
73100

74101
cy.wait(['@foo', '@bar'])
75-
.spread((first, second) => {
102+
.then(([first, second]) => {
76103
first // $ExpectType WaitXHR
77104
})
78105

79106
cy.wrap([{ foo: 'bar' }, { foo: 'baz' }])
80107
.then(subject => {
81108
subject // $ExpectType { foo: string; }[]
82109
})
83-
.spread((first, second) => {
110+
.then(([first, second]) => {
84111
first // $ExpectType { foo: string; }
85112
})
86113
.then(subject => {
87114
subject // $ExpectType { foo: string; }[]
88115
})
89-
.spread((first, second) => {
116+
.then(([first, second]) => {
90117
return first.foo + second.foo
91118
})
92119
.then(subject => {
93120
subject // $ExpectType string
94121
})
95122

96-
cy.wrap([1, 2, 3]).each((num, i, array) => {
123+
cy.wrap([1, 2, 3]).each((num: number, i, array) => {
97124
return new Cypress.Promise((resolve) => {
98125
setTimeout(() => {
99126
resolve()

0 commit comments

Comments
 (0)