Skip to content

Commit 0bb655e

Browse files
sainthkhflotwigjennifer-shehaneRacheltbiethman
authored
chore: remove command type todos (#20601)
Co-authored-by: Zach Bloomquist <[email protected]> Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Rachel <[email protected]> Co-authored-by: Tyler Biethman <[email protected]>
1 parent 342bc06 commit 0bb655e

27 files changed

+349
-214
lines changed

cli/types/cypress.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2519,7 +2519,7 @@ declare namespace Cypress {
25192519
action: 'select' | 'drag-drop'
25202520
}
25212521

2522-
interface BlurOptions extends Loggable, Forceable { }
2522+
interface BlurOptions extends Loggable, Timeoutable, Forceable { }
25232523

25242524
interface CheckOptions extends Loggable, Timeoutable, ActionableOptions {
25252525
interval: number

packages/driver/cypress/integration/commands/screenshot_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,9 @@ describe('src/cy/commands/screenshot', () => {
761761
cy.get('.short-element').within(() => {
762762
cy.screenshot({ capture: 'runner' })
763763
}).then(() => {
764-
// the runner was captured
765-
expect(Cypress.action.withArgs('cy:before:screenshot').args[0][1].appOnly).to.be.true
766-
expect(Cypress.automation.withArgs('take:screenshot').args[0][1].capture).to.equal('viewport')
764+
// the runner was captured ("appOnly === true" means to hide the runner UI)
765+
expect(Cypress.action.withArgs('cy:before:screenshot').args[0][1].appOnly).to.be.false
766+
expect(Cypress.automation.withArgs('take:screenshot').args[0][1].capture).to.equal('runner')
767767
})
768768
})
769769

packages/driver/src/cy/commands/actions/focus.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,29 @@ import $dom from '../../../dom'
44
import $utils from '../../../cypress/utils'
55
import $errUtils from '../../../cypress/error_utils'
66
import $elements from '../../../dom/elements'
7+
import type { Log } from '../../../cypress/log'
8+
9+
interface InternalFocusOptions extends Partial<Cypress.Loggable & Cypress.Timeoutable> {
10+
_log?: Log
11+
$el: JQuery
12+
error: boolean
13+
verify: boolean
14+
}
15+
16+
interface InternalBlurOptions extends Partial<Cypress.BlurOptions> {
17+
_log?: Log
18+
$el: JQuery
19+
$focused: JQuery
20+
error: boolean
21+
verify: boolean
22+
}
723

824
export default (Commands, Cypress, cy) => {
925
return Commands.addAll({ prevSubject: ['element', 'window'] }, {
10-
// TODO: any -> Partial<Cypress.Loggable & Cypress.Timeoutable>
11-
focus (subject, options: any = {}) {
12-
const userOptions = options
13-
26+
focus (subject, userOptions: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
1427
// we should throw errors by default!
1528
// but allow them to be silenced
16-
options = _.defaults({}, userOptions, {
29+
const options: InternalFocusOptions = _.defaults({}, userOptions, {
1730
$el: subject,
1831
error: true,
1932
log: true,
@@ -85,13 +98,10 @@ export default (Commands, Cypress, cy) => {
8598
return verifyAssertions()
8699
},
87100

88-
// TODO: any -> Partial<Cypress.BlurOptions>
89-
blur (subject, options: any = {}) {
90-
const userOptions = options
91-
101+
blur (subject, userOptions: Partial<Cypress.BlurOptions> = {}) {
92102
// we should throw errors by default!
93103
// but allow them to be silenced
94-
options = _.defaults({}, userOptions, {
104+
const options: InternalBlurOptions = _.defaults({}, userOptions, {
95105
$el: subject,
96106
$focused: cy.getFocused(),
97107
error: true,

packages/driver/src/cy/commands/actions/scroll.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Promise from 'bluebird'
55
import $dom from '../../../dom'
66
import $utils from '../../../cypress/utils'
77
import $errUtils from '../../../cypress/error_utils'
8+
import type { Log } from '../../../cypress/log'
89

910
const findScrollableParent = ($el, win) => {
1011
const $parent = $dom.getParent($el)
@@ -28,12 +29,26 @@ const isNaNOrInfinity = (item) => {
2829
return _.isNaN(num) || !_.isFinite(num)
2930
}
3031

32+
interface InternalScrollIntoViewOptions extends Partial<Cypress.ScrollToOptions> {
33+
_log?: Log
34+
$el: JQuery
35+
$parent: any
36+
axis: string
37+
offset?: object
38+
}
39+
40+
interface InternalScrollToOptions extends Partial<Cypress.ScrollToOptions> {
41+
_log?: Log
42+
$el: any
43+
x: number
44+
y: number
45+
error?: any
46+
axis: string
47+
}
48+
3149
export default (Commands, Cypress, cy, state) => {
3250
Commands.addAll({ prevSubject: 'element' }, {
33-
// TODO: any -> Partial<Cypress.ScrollToOptions>
34-
scrollIntoView (subject, options: any = {}) {
35-
const userOptions = options
36-
51+
scrollIntoView (subject, userOptions: Partial<Cypress.ScrollToOptions> = {}) {
3752
if (!_.isObject(userOptions)) {
3853
$errUtils.throwErrByPath('scrollIntoView.invalid_argument', { args: { arg: userOptions } })
3954
}
@@ -49,7 +64,7 @@ export default (Commands, Cypress, cy, state) => {
4964
$errUtils.throwErrByPath('scrollIntoView.multiple_elements', { args: { num: subject.length } })
5065
}
5166

52-
options = _.defaults({}, userOptions, {
67+
const options: InternalScrollIntoViewOptions = _.defaults({}, userOptions, {
5368
$el: subject,
5469
$parent: state('window'),
5570
log: true,
@@ -115,9 +130,6 @@ export default (Commands, Cypress, cy, state) => {
115130
const scrollIntoView = () => {
116131
return new Promise((resolve, reject) => {
117132
// scroll our axes
118-
// TODO: done() came from jQuery animate(), specifically, EffectsOptions at misc.d.ts
119-
// The type definition should be fixed at @types/jquery.scrollto.
120-
// @ts-ignore
121133
return $(options.$parent).scrollTo(options.$el, {
122134
axis: options.axis,
123135
easing: options.easing,
@@ -157,10 +169,8 @@ export default (Commands, Cypress, cy, state) => {
157169
})
158170

159171
Commands.addAll({ prevSubject: ['optional', 'element', 'window'] }, {
160-
// TODO: any -> Partial<Cypress.ScrollToOptions>
161-
scrollTo (subject, xOrPosition, yOrOptions, options: any = {}) {
172+
scrollTo (subject, xOrPosition, yOrOptions, userOptions: Partial<Cypress.ScrollToOptions> = {}) {
162173
let x; let y
163-
let userOptions = options
164174

165175
// check for undefined or null values
166176
if (xOrPosition === undefined || xOrPosition === null) {
@@ -261,7 +271,7 @@ export default (Commands, Cypress, cy, state) => {
261271
$errUtils.throwErrByPath('scrollTo.multiple_containers', { args: { num: $container.length } })
262272
}
263273

264-
options = _.defaults({}, userOptions, {
274+
const options: InternalScrollToOptions = _.defaults({}, userOptions, {
265275
$el: $container,
266276
log: true,
267277
duration: 0,
@@ -361,10 +371,7 @@ export default (Commands, Cypress, cy, state) => {
361371

362372
const scrollTo = () => {
363373
return new Promise((resolve, reject) => {
364-
// scroll our axis'
365-
// TODO: done() came from jQuery animate(), specifically, EffectsOptions at misc.d.ts
366-
// The type definition should be fixed at @types/jquery.scrollto.
367-
// @ts-ignore
374+
// scroll our axis
368375
$(options.$el).scrollTo({ left: x, top: y }, {
369376
axis: options.axis,
370377
easing: options.easing,

packages/driver/src/cy/commands/actions/select.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import $dom from '../../../dom'
55
import $utils from '../../../cypress/utils'
66
import $errUtils from '../../../cypress/error_utils'
77
import $elements from '../../../dom/elements'
8+
import type { Log } from '../../../cypress/log'
89

910
const newLineRe = /\n/g
1011

12+
interface InternalSelectOptions extends Partial<Cypress.SelectOptions> {
13+
_log?: Log
14+
$el: JQuery<HTMLSelectElement>
15+
error?: any
16+
}
17+
1118
export default (Commands, Cypress, cy) => {
1219
Commands.addAll({ prevSubject: 'element' }, {
13-
// TODO: any -> Partial<Cypress.SelectOptions>
14-
select (subject, valueOrTextOrIndex, options: any = {}) {
20+
select (subject, valueOrTextOrIndex, userOptions: Partial<Cypress.SelectOptions> = {}) {
1521
if (
1622
!_.isNumber(valueOrTextOrIndex)
1723
&& !_.isString(valueOrTextOrIndex)
@@ -28,9 +34,7 @@ export default (Commands, Cypress, cy) => {
2834
$errUtils.throwErrByPath('select.invalid_array_argument', { args: { value: JSON.stringify(valueOrTextOrIndex) } })
2935
}
3036

31-
const userOptions = options
32-
33-
options = _.defaults({}, userOptions, {
37+
const options: InternalSelectOptions = _.defaults({}, userOptions, {
3438
$el: subject,
3539
log: true,
3640
force: false,
@@ -55,7 +59,7 @@ export default (Commands, Cypress, cy) => {
5559
},
5660
})
5761

58-
options._log.snapshot('before', { next: 'after' })
62+
options._log!.snapshot('before', { next: 'after' })
5963
}
6064

6165
let node

packages/driver/src/cy/commands/actions/submit.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ import $dom from '../../../dom'
55
import $utils from '../../../cypress/utils'
66
import $errUtils from '../../../cypress/error_utils'
77
import $actionability from '../../actionability'
8+
import type { Log } from '../../../cypress/log'
9+
10+
interface InternalSubmitOptions extends Partial<Cypress.Loggable & Cypress.Timeoutable>{
11+
_log?: Log
12+
$el: JQuery<HTMLFormElement>
13+
}
814

915
export default (Commands, Cypress, cy) => {
1016
Commands.addAll({ prevSubject: 'element' }, {
11-
// TODO: any -> Partial<Cypress.Loggable & Cypress.Timeoutable>
12-
submit (subject, options: any = {}) {
13-
const userOptions = options
14-
15-
options = _.defaults({}, userOptions, {
17+
submit (subject: JQuery<HTMLFormElement>, userOptions: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
18+
const options: InternalSubmitOptions = _.defaults({}, userOptions, {
1619
log: true,
1720
$el: subject,
1821
})
@@ -35,7 +38,7 @@ export default (Commands, Cypress, cy) => {
3538
},
3639
})
3740

38-
options._log.snapshot('before', { next: 'after' })
41+
options._log!.snapshot('before', { next: 'after' })
3942
}
4043

4144
if (!options.$el.is('form')) {

packages/driver/src/cy/commands/actions/type.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,33 @@ import $utils from '../../../cypress/utils'
88
import $errUtils from '../../../cypress/error_utils'
99
import $actionability from '../../actionability'
1010
import $Keyboard from '../../../cy/keyboard'
11+
import type { Log } from '../../../cypress/log'
12+
1113
import debugFn from 'debug'
1214
const debug = debugFn('cypress:driver:command:type')
1315

16+
interface InternalTypeOptions extends Partial<Cypress.TypeOptions> {
17+
_log?: Log
18+
$el: JQuery
19+
ensure?: object
20+
verify: boolean
21+
interval?: number
22+
}
23+
24+
interface InternalClearOptions extends Partial<Cypress.ClearOptions> {
25+
_log?: Log
26+
ensure?: object
27+
}
28+
1429
export default function (Commands, Cypress, cy, state, config) {
1530
const { keyboard } = cy.devices
1631

17-
// Note: These "change type of `any` to X" comments are written instead of changing them directly
18-
// because Cypress extends user-given options with Cypress internal options.
19-
// These comments will be removed after removing `// @ts-nocheck` comments in `packages/driver`.
20-
// TODO: change the type of `any` to `Partial<Cypress.TypeOptions>`
21-
function type (subject, chars, options: any = {}) {
22-
const userOptions = options
32+
function type (subject, chars, userOptions: Partial<Cypress.TypeOptions> = {}) {
2333
let updateTable
2434

2535
// allow the el we're typing into to be
2636
// changed by options -- used by cy.clear()
27-
options = _.defaults({}, userOptions, {
37+
const options: InternalTypeOptions = _.defaults({}, userOptions, {
2838
$el: subject,
2939
log: true,
3040
verify: true,
@@ -110,7 +120,7 @@ export default function (Commands, Cypress, cy, state, config) {
110120
},
111121
})
112122

113-
options._log.snapshot('before', { next: 'after' })
123+
options._log!.snapshot('before', { next: 'after' })
114124
}
115125

116126
if (options.$el.length > 1) {
@@ -572,11 +582,8 @@ export default function (Commands, Cypress, cy, state, config) {
572582
})
573583
}
574584

575-
// TODO: change the type of `any` to `Partial<ClearOptions>`
576-
function clear (subject, options: any = {}) {
577-
const userOptions = options
578-
579-
options = _.defaults({}, userOptions, {
585+
function clear (subject, userOptions: Partial<Cypress.ClearOptions> = {}) {
586+
const options: InternalClearOptions = _.defaults({}, userOptions, {
580587
log: true,
581588
force: false,
582589
waitForAnimations: config('waitForAnimations'),

packages/driver/src/cy/commands/angular.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import $ from 'jquery'
33
import Promise from 'bluebird'
44

55
import $errUtils from '../../cypress/error_utils'
6+
import type { Log } from '../../cypress/log'
67

78
const ngPrefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-']
89

10+
interface InternalNgOptions extends Partial<Cypress.Loggable & Cypress.Timeoutable> {
11+
_log?: Log
12+
}
13+
914
export default (Commands, Cypress, cy, state) => {
1015
const findByNgBinding = (binding, options) => {
1116
const selector = '.ng-binding'
@@ -89,10 +94,7 @@ export default (Commands, Cypress, cy, state) => {
8994
}
9095

9196
Commands.addAll({
92-
// TODO: Change the options type from `any` to `Partial<Cypress.Loggable & Cypress.Timeoutable>`.
93-
ng (type, selector, options: any = {}) {
94-
const userOptions = options
95-
97+
ng (type: string, selector: string, userOptions: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
9698
// what about requirejs / browserify?
9799
// we need to intelligently check to see if we're using those
98100
// and if angular is available through them. throw a very specific
@@ -102,7 +104,7 @@ export default (Commands, Cypress, cy, state) => {
102104
$errUtils.throwErrByPath('ng.no_global')
103105
}
104106

105-
options = _.defaults({}, userOptions, { log: true })
107+
const options: InternalNgOptions = _.defaults({}, userOptions, { log: true })
106108

107109
if (options.log) {
108110
options._log = Cypress.log({

packages/driver/src/cy/commands/clock.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export default function (Commands, Cypress, cy, state) {
4242
})
4343

4444
return Commands.addAll({ type: 'utility' }, {
45-
// TODO: change the options type from `any` to Partial<Loggable>.
46-
clock (subject, now, methods, options: any = {}) {
45+
clock (subject, now, methods, options: Partial<Cypress.Loggable> = {}) {
4746
let userOptions = options
4847
const ctx = state('ctx')
4948

0 commit comments

Comments
 (0)