From 5a99e374606699d9de0184c376548d7e8e3785db Mon Sep 17 00:00:00 2001 From: Ahmed Tarek Date: Sat, 16 Apr 2022 00:40:31 +0200 Subject: [PATCH 1/3] fix: prevObject types --- cli/types/cypress.d.ts | 11 ++++++++--- cli/types/tests/cypress-tests.ts | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index bfb7c84822fd..9c06661de532 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -10,10 +10,13 @@ declare namespace Cypress { type PrevSubject = keyof PrevSubjectMap type TestingType = 'e2e' | 'component' type PluginConfig = (on: PluginEvents, config: PluginConfigOptions) => void | ConfigOptions | Promise + interface JQueryWithSelector extends JQuery { + selector?: string | null + } interface PrevSubjectMap { optional: O - element: JQuery + element: JQueryWithSelector document: Document window: Window } @@ -467,16 +470,18 @@ declare namespace Cypress { Commands: { add(name: T, fn: CommandFn): void add(name: T, options: CommandOptions & {prevSubject: false}, fn: CommandFn): void + add(name: T, options: CommandOptions & {prevSubject: true}, fn: CommandFnWithSubject): void add( - name: T, options: CommandOptions & { prevSubject: true | S | ['optional'] }, fn: CommandFnWithSubject, + name: T, options: CommandOptions & { prevSubject: S | ['optional'] }, fn: CommandFnWithSubject, ): void add( name: T, options: CommandOptions & { prevSubject: S[] }, fn: CommandFnWithSubject[S]>, ): void addAll(fns: CommandFns): void addAll(options: CommandOptions & {prevSubject: false}, fns: CommandFns): void + addAll(options: CommandOptions & { prevSubject: true }, fns: CommandFnsWithSubject): void addAll( - options: CommandOptions & { prevSubject: true | S | ['optional'] }, fns: CommandFnsWithSubject, + options: CommandOptions & { prevSubject: S | ['optional'] }, fns: CommandFnsWithSubject, ): void addAll( options: CommandOptions & { prevSubject: S[] }, fns: CommandFnsWithSubject[S]>, diff --git a/cli/types/tests/cypress-tests.ts b/cli/types/tests/cypress-tests.ts index eecb36f65909..d1992f829f6e 100644 --- a/cli/types/tests/cypress-tests.ts +++ b/cli/types/tests/cypress-tests.ts @@ -83,7 +83,7 @@ namespace CypressCommandsTests { arg // $ExpectType string }) Cypress.Commands.add('newCommand', { prevSubject: true }, (subject, arg) => { - subject // $ExpectType unknown + subject // $ExpectType any arg // $ExpectType string return }) @@ -113,11 +113,11 @@ namespace CypressCommandsTests { arg // $ExpectType string }) Cypress.Commands.add('newCommand', { prevSubject: 'element' }, (subject, arg) => { - subject // $ExpectType JQuery + subject // $ExpectType JQueryWithSelector arg // $ExpectType string }) Cypress.Commands.add('newCommand', { prevSubject: ['element'] }, (subject, arg) => { - subject // $ExpectType JQuery + subject // $ExpectType JQueryWithSelector arg // $ExpectType string }) Cypress.Commands.add('newCommand', { prevSubject: ['element', 'document', 'window'] }, (subject, arg) => { @@ -126,7 +126,7 @@ namespace CypressCommandsTests { } else if (subject instanceof Document) { subject // $ExpectType Document } else { - subject // $ExpectType JQuery + subject // $ExpectType JQueryWithSelector } arg // $ExpectType string }) @@ -136,7 +136,7 @@ namespace CypressCommandsTests { } else if (subject instanceof Document) { subject // $ExpectType Document } else if (subject) { - subject // $ExpectType JQuery + subject // $ExpectType JQueryWithSelector } else { subject // $ExpectType void } @@ -173,7 +173,7 @@ namespace CypressCommandsTests { }) Cypress.Commands.addAll({ prevSubject: true }, { newCommand: (subject, arg) => { - subject // $ExpectType unknown + subject // $ExpectType any arg // $ExpectType any return }, @@ -215,13 +215,13 @@ namespace CypressCommandsTests { }) Cypress.Commands.addAll({ prevSubject: 'element' }, { newCommand: (subject, arg) => { - subject // $ExpectType JQuery + subject // $ExpectType JQueryWithSelector arg // $ExpectType any } }) Cypress.Commands.addAll({ prevSubject: ['element'] }, { newCommand: (subject, arg) => { - subject // $ExpectType JQuery + subject // $ExpectType JQueryWithSelector arg // $ExpectType any } }) @@ -232,7 +232,7 @@ namespace CypressCommandsTests { } else if (subject instanceof Document) { subject // $ExpectType Document } else { - subject // $ExpectType JQuery + subject // $ExpectType JQueryWithSelector } arg // $ExpectType any } @@ -244,7 +244,7 @@ namespace CypressCommandsTests { } else if (subject instanceof Document) { subject // $ExpectType Document } else if (subject) { - subject // $ExpectType JQuery + subject // $ExpectType JQueryWithSelector } else { subject // $ExpectType void } @@ -271,7 +271,7 @@ namespace CypressCommandsTests { originalFn.apply(this, [arg]) // $ExpectType Chainable }) Cypress.Commands.overwrite<'type', 'element'>('type', (originalFn, element, text, options?: Partial) => { - element // $ExpectType JQuery + element // $ExpectType JQueryWithSelector text // $ExpectType string if (options && options.sensitive) { From 8ed3bfadcd52527e95aec528bdd2682a145a48b2 Mon Sep 17 00:00:00 2001 From: Ahmed Tarek Date: Sat, 16 Apr 2022 00:50:08 +0200 Subject: [PATCH 2/3] Empty-Commit From 6a3e429cf6be857d4c747056a929500c097ce94c Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Mon, 18 Apr 2022 10:19:03 -0500 Subject: [PATCH 3/3] Update cli/types/cypress.d.ts --- cli/types/cypress.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 9c06661de532..2e576727860b 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -10,7 +10,7 @@ declare namespace Cypress { type PrevSubject = keyof PrevSubjectMap type TestingType = 'e2e' | 'component' type PluginConfig = (on: PluginEvents, config: PluginConfigOptions) => void | ConfigOptions | Promise - interface JQueryWithSelector extends JQuery { + interface JQueryWithSelector extends JQuery { selector?: string | null }