From 87cd046b8d4d11a8c228435b0364220f2e920bc1 Mon Sep 17 00:00:00 2001 From: Tyler Biethman Date: Fri, 15 Apr 2022 14:07:03 -0500 Subject: [PATCH] Revert "fix: types for Cypress.Commands.add (#20376) (#20377)" This reverts commit 92d94252ca90c10d65b4d8ce4a5b6bbebed87b18. --- cli/types/cypress.d.ts | 9 +++------ cli/types/tests/cypress-tests.ts | 15 ++++++--------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 7988514d92e5..bfb7c84822fd 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -10,12 +10,10 @@ 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: JQueryWithSelector + element: JQuery document: Document window: Window } @@ -469,9 +467,8 @@ 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: S | ['optional'] }, fn: CommandFnWithSubject, + name: T, options: CommandOptions & { prevSubject: true | S | ['optional'] }, fn: CommandFnWithSubject, ): void add( name: T, options: CommandOptions & { prevSubject: S[] }, fn: CommandFnWithSubject[S]>, diff --git a/cli/types/tests/cypress-tests.ts b/cli/types/tests/cypress-tests.ts index 9c8bf219cff7..eecb36f65909 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 any + subject // $ExpectType unknown arg // $ExpectType string return }) @@ -113,13 +113,11 @@ namespace CypressCommandsTests { arg // $ExpectType string }) Cypress.Commands.add('newCommand', { prevSubject: 'element' }, (subject, arg) => { - subject // $ExpectType JQueryWithSelector - subject.selector // $ExpectType string | null | undefined + subject // $ExpectType JQuery arg // $ExpectType string }) Cypress.Commands.add('newCommand', { prevSubject: ['element'] }, (subject, arg) => { - subject // $ExpectType JQueryWithSelector - subject.selector // $ExpectType string | null | undefined + subject // $ExpectType JQuery arg // $ExpectType string }) Cypress.Commands.add('newCommand', { prevSubject: ['element', 'document', 'window'] }, (subject, arg) => { @@ -128,8 +126,7 @@ namespace CypressCommandsTests { } else if (subject instanceof Document) { subject // $ExpectType Document } else { - subject // $ExpectType JQueryWithSelector - subject.selector // $ExpectType string | null | undefined + subject // $ExpectType JQuery } arg // $ExpectType string }) @@ -139,7 +136,7 @@ namespace CypressCommandsTests { } else if (subject instanceof Document) { subject // $ExpectType Document } else if (subject) { - subject // $ExpectType JQueryWithSelector + subject // $ExpectType JQuery } else { subject // $ExpectType void } @@ -274,7 +271,7 @@ namespace CypressCommandsTests { originalFn.apply(this, [arg]) // $ExpectType Chainable }) Cypress.Commands.overwrite<'type', 'element'>('type', (originalFn, element, text, options?: Partial) => { - element // $ExpectType JQueryWithSelector + element // $ExpectType JQuery text // $ExpectType string if (options && options.sensitive) {