Skip to content

Commit bf0d4db

Browse files
sainthkhemilyrohrboughflotwig
authored
chore: Remove pkg/driver //@ts-nocheck part 3 (#19837)
Co-authored-by: Emily Rohrbough <[email protected]> Co-authored-by: Zach Bloomquist <[email protected]>
1 parent bc6d240 commit bf0d4db

File tree

20 files changed

+159
-120
lines changed

20 files changed

+159
-120
lines changed

packages/driver/src/config/jquery.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
// @ts-nocheck
2-
3-
import $ from 'jquery'
1+
import JQuery from 'jquery'
42
import _ from 'lodash'
53

64
import { scrollTo } from './jquery.scrollto'
75
import $dom from '../dom'
86

7+
// Add missing types.
8+
interface ExtendedJQueryStatic extends JQueryStatic {
9+
find: any
10+
expr: JQuery.Selectors & { filters: any }
11+
}
12+
13+
const $: ExtendedJQueryStatic = JQuery as any
14+
915
// force jquery to have the same visible
1016
// and hidden logic as cypress
1117

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
import _ from 'lodash'
32
import Promise from 'bluebird'
43

@@ -7,7 +6,7 @@ import $utils from '../../../cypress/utils'
76
import $errUtils from '../../../cypress/error_utils'
87
import $elements from '../../../dom/elements'
98

10-
const checkOrUncheck = (Cypress, cy, type, subject, values = [], userOptions = {}) => {
9+
const checkOrUncheck = (Cypress, cy, type, subject, values: any[] = [], userOptions = {}) => {
1110
// we're not handling conversion of values to strings
1211
// in case we've received numbers
1312

@@ -18,15 +17,15 @@ const checkOrUncheck = (Cypress, cy, type, subject, values = [], userOptions = {
1817
values = []
1918
} else {
2019
// make sure we're an array of values
21-
values = [].concat(values)
20+
values = ([] as any[]).concat(values)
2221
}
2322

2423
// keep an array of subjects which
2524
// are potentially reduced down
2625
// to new filtered subjects
27-
const matchingElements = []
26+
const matchingElements: HTMLElement[] = []
2827

29-
const options = _.defaults({}, userOptions, {
28+
const options: Record<string, any> = _.defaults({}, userOptions, {
3029
$el: subject,
3130
log: true,
3231
force: false,
@@ -75,7 +74,7 @@ const checkOrUncheck = (Cypress, cy, type, subject, values = [], userOptions = {
7574
matchingElements.push(el)
7675
}
7776

78-
const consoleProps = {
77+
const consoleProps: Record<string, any> = {
7978
'Applied To': $dom.getElements($el),
8079
'Elements': $el.length,
8180
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-nocheck
2-
31
import _ from 'lodash'
42
import Promise from 'bluebird'
53

@@ -59,7 +57,7 @@ export default (Commands, Cypress, cy, state, config) => {
5957

6058
({ options: userOptions, position, x, y } = $actionability.getPositionFromArguments(positionOrX, y, userOptions))
6159

62-
const options = _.defaults({}, userOptions, {
60+
const options: Record<string, any> = _.defaults({}, userOptions, {
6361
log: true,
6462
$el: subject,
6563
bubbles: true,

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
import _ from 'lodash'
32
import Promise from 'bluebird'
43

@@ -15,7 +14,11 @@ const debug = debugFn('cypress:driver:command:type')
1514
export default function (Commands, Cypress, cy, state, config) {
1615
const { keyboard } = cy.devices
1716

18-
function type (subject, chars, options = {}) {
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 = {}) {
1922
const userOptions = options
2023
let updateTable
2124

@@ -366,7 +369,7 @@ export default function (Commands, Cypress, cy, state, config) {
366369
// Firefox sends a click event automatically.
367370
if (!Cypress.isBrowser('firefox')) {
368371
const ctor = $dom.getDocumentFromElement(el).defaultView?.PointerEvent
369-
const event = new ctor('click')
372+
const event = new ctor!('click')
370373

371374
el.dispatchEvent(event)
372375
}
@@ -510,7 +513,8 @@ export default function (Commands, Cypress, cy, state, config) {
510513
})
511514
}
512515

513-
function clear (subject, options = {}) {
516+
// TODO: change the type of `any` to `Partial<ClearOptions>`
517+
function clear (subject, options: any = {}) {
514518
const userOptions = options
515519

516520
options = _.defaults({}, userOptions, {

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
// @ts-nocheck
2-
31
import _ from 'lodash'
42
import Promise from 'bluebird'
53

64
import $dom from '../../dom'
75
import $utils from '../../cypress/utils'
8-
import $errUtils from '../../cypress/error_utils'
6+
import $errUtils, { CypressError } from '../../cypress/error_utils'
97

10-
const returnFalseIfThenable = (key, ...args) => {
8+
const returnFalseIfThenable = (key, ...args): boolean => {
119
if ((key === 'then') && _.isFunction(args[0]) && _.isFunction(args[1])) {
1210
// https://github.com/cypress-io/cypress/issues/111
1311
// if we're inside of a promise then the promise lib will naturally
@@ -22,6 +20,8 @@ const returnFalseIfThenable = (key, ...args) => {
2220

2321
return false
2422
}
23+
24+
return true
2525
}
2626

2727
const primitiveToObject = (memo) => {
@@ -181,7 +181,7 @@ export default function (Commands, Cypress, cy, state) {
181181

182182
const invokeFn = (subject, userOptionsOrStr, ...args) => {
183183
const userOptionsPassed = _.isObject(userOptionsOrStr) && !_.isFunction(userOptionsOrStr)
184-
let userOptions = null
184+
let userOptions: Record<string, any> | null = null
185185
let str = null
186186

187187
if (!userOptionsPassed) {
@@ -219,7 +219,7 @@ export default function (Commands, Cypress, cy, state) {
219219

220220
const message = getMessage()
221221

222-
let traversalErr = null
222+
let traversalErr: CypressError | null = null
223223

224224
// copy userOptions because _log is added below.
225225
const options = _.extend({}, userOptions)
@@ -568,7 +568,7 @@ export default function (Commands, Cypress, cy, state) {
568568
return ret
569569
}
570570

571-
return thenFn(el, userOptions, callback, state)
571+
return thenFn(el, userOptions, callback)
572572
}
573573

574574
// generate a real array since bluebird is finicky and
@@ -586,9 +586,9 @@ export default function (Commands, Cypress, cy, state) {
586586
// cy.resolve + cy.wrap are upgraded to handle
587587
// promises
588588
Commands.addAll({ prevSubject: 'optional' }, {
589-
then () {
589+
then (subject, userOptions, fn) {
590590
// eslint-disable-next-line prefer-rest-params
591-
return thenFn.apply(this, arguments)
591+
return thenFn.apply(this, [subject, userOptions, fn])
592592
},
593593
})
594594

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-nocheck
2-
31
import _ from 'lodash'
42
import Promise from 'bluebird'
53

@@ -110,7 +108,7 @@ export default function (Commands, Cypress, cy, state, config) {
110108
})
111109
}
112110

113-
const getAndClear = (log, timeout, options = {}) => {
111+
const getAndClear = (log?, timeout?, options = {}) => {
114112
return automateCookies('get:cookies', options, log, timeout)
115113
.then((resp) => {
116114
// bail early if we got no cookies!
@@ -166,7 +164,8 @@ export default function (Commands, Cypress, cy, state, config) {
166164
})
167165

168166
return Commands.addAll({
169-
getCookie (name, options = {}) {
167+
// TODO: change the type of `any` to `Partial<Cypress.Loggable & Cypress.Timeoutable>`
168+
getCookie (name, options: any = {}) {
170169
const userOptions = options
171170

172171
options = _.defaults({}, userOptions, {
@@ -212,7 +211,8 @@ export default function (Commands, Cypress, cy, state, config) {
212211
.catch(handleBackendError('getCookie', 'reading the requested cookie from', onFail))
213212
},
214213

215-
getCookies (options = {}) {
214+
// TODO: change the type of `any` to `Partial<Cypress.Loggable & Cypress.Timeoutable>`
215+
getCookies (options: any = {}) {
216216
const userOptions = options
217217

218218
options = _.defaults({}, userOptions, {
@@ -250,7 +250,8 @@ export default function (Commands, Cypress, cy, state, config) {
250250
.catch(handleBackendError('getCookies', 'reading cookies from', options._log))
251251
},
252252

253-
setCookie (name, value, options = {}) {
253+
// TODO: change the type of `any` to `Partial<Cypress.SetCookieOptions>`
254+
setCookie (name, value, options: any = {}) {
254255
const userOptions = options
255256

256257
options = _.defaults({}, userOptions, {
@@ -331,7 +332,8 @@ export default function (Commands, Cypress, cy, state, config) {
331332
}).catch(handleBackendError('setCookie', 'setting the requested cookie in', onFail))
332333
},
333334

334-
clearCookie (name, options = {}) {
335+
// TODO: change the type of `any` to `Partial<Cypress.Loggable & Cypress.Timeoutable>`
336+
clearCookie (name, options: any = {}) {
335337
const userOptions = options
336338

337339
options = _.defaults({}, userOptions, {
@@ -380,7 +382,8 @@ export default function (Commands, Cypress, cy, state, config) {
380382
.catch(handleBackendError('clearCookie', 'clearing the requested cookie in', onFail))
381383
},
382384

383-
clearCookies (options = {}) {
385+
// TODO: change the type of `any` to `Partial<Cypress.Loggable & Cypress.Timeoutable>`
386+
clearCookies (options: any = {}) {
384387
const userOptions = options
385388

386389
options = _.defaults({}, userOptions, {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
// @ts-nocheck
2-
31
import _ from 'lodash'
42
import Promise from 'bluebird'
53

64
import $errUtils from '../../cypress/error_utils'
75

86
export default (Commands, Cypress, cy) => {
97
Commands.addAll({
10-
exec (cmd, options = {}) {
8+
// TODO: change the type of `any` to `Partical<Cypress.ExecOptions>`
9+
exec (cmd, options: any = {}) {
1110
const userOptions = options
1211

1312
options = _.defaults({}, userOptions, {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// @ts-nocheck
21
import _ from 'lodash'
32
import { basename } from 'path'
43

54
import $errUtils from '../../cypress/error_utils'
65

76
export default (Commands, Cypress, cy, state) => {
87
Commands.addAll({
9-
readFile (file, encoding, options = {}) {
8+
// TODO: change the type of `any` to `Partial<Cypress.Loggable & Cypress.Timeoutable>`
9+
readFile (file, encoding, options: any = {}) {
1010
let userOptions = options
1111

1212
if (_.isObject(encoding)) {
@@ -109,7 +109,8 @@ export default (Commands, Cypress, cy, state) => {
109109
return verifyAssertions()
110110
},
111111

112-
writeFile (fileName, contents, encoding, options = {}) {
112+
// TODO: change the type of `any` to `Partial<Cypress.WriteFileOPtions & Cypress.Timeoutable>`
113+
writeFile (fileName, contents, encoding, options: any = {}) {
113114
let userOptions = options
114115

115116
if (_.isObject(encoding)) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-nocheck
2-
31
import _ from 'lodash'
42
import Promise from 'bluebird'
53
import { basename } from 'path'
@@ -44,7 +42,7 @@ export default (Commands, Cypress, cy, state, config) => {
4442
return Promise.resolve(clone(resp))
4543
}
4644

47-
let options = {}
45+
let options: Record<string, any> = {}
4846

4947
if (_.isObject(args[0])) {
5048
options = args[0]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-nocheck
2-
31
import _ from 'lodash'
42
import Promise from 'bluebird'
53

@@ -8,7 +6,8 @@ const { throwErrByPath } = $errUtils
86

97
export default (Commands, Cypress, cy) => {
108
Commands.addAll({
11-
url (options = {}) {
9+
// TODO: change the type of `any` to `Partial<Cypress.UrlOptions>`
10+
url (options: any = {}) {
1211
const userOptions = options
1312

1413
options = _.defaults({}, userOptions, { log: true })
@@ -39,7 +38,8 @@ export default (Commands, Cypress, cy) => {
3938
return resolveHref()
4039
},
4140

42-
hash (options = {}) {
41+
// TODO: change the type of `any` to `Partial<Cypress.Loggable & Cypress.Timeoutable>`
42+
hash (options: any = {}) {
4343
const userOptions = options
4444

4545
options = _.defaults({}, userOptions, { log: true })

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
import _ from 'lodash'
32
import Promise from 'bluebird'
43

@@ -50,7 +49,8 @@ export default (Commands, Cypress, cy, state) => {
5049
return null
5150
},
5251

53-
wrap (arg, options = {}) {
52+
// TODO: change the type of `any` to `Partial<Cypress.Loggable & Cypress.Timeoutable>`
53+
wrap (arg, options: any = {}) {
5454
const userOptions = options
5555

5656
options = _.defaults({}, userOptions, {

0 commit comments

Comments
 (0)