Skip to content

Commit af472b6

Browse files
sainthkhflotwig
andauthored
fix: revive type checker (#18172)
Co-authored-by: Zach Bloomquist <github@chary.us>
1 parent bc21574 commit af472b6

File tree

78 files changed

+45918
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+45918
-161
lines changed

cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@types/jquery": "3.3.31",
7575
"@types/lodash": "4.14.168",
7676
"@types/minimatch": "3.0.3",
77-
"@types/mocha": "5.2.7",
77+
"@types/mocha": "8.0.3",
7878
"@types/sinon": "7.5.1",
7979
"@types/sinon-chai": "3.2.5",
8080
"chai": "3.5.0",

cli/scripts/post-install.js

+21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
const { includeTypes } = require('./utils')
77
const shell = require('shelljs')
8+
const fs = require('fs')
89
const { join } = require('path')
910
const resolvePkg = require('resolve-pkg')
1011

@@ -72,3 +73,23 @@ shell.sed('-i', 'from \'sinon\';', 'from \'../sinon\';', sinonChaiFilename)
7273
// copy experimental network stubbing type definitions
7374
// so users can import: `import 'cypress/types/net-stubbing'`
7475
shell.cp(resolvePkg('@packages/net-stubbing/lib/external-types.ts'), 'types/net-stubbing.ts')
76+
77+
// https://github.com/cypress-io/cypress/issues/18069
78+
// To avoid type clashes, some files should be commented out entirely by patch-package
79+
// and uncommented here.
80+
81+
const filesToUncomment = [
82+
'mocha/index.d.ts',
83+
'jquery/JQuery.d.ts',
84+
'jquery/legacy.d.ts',
85+
'jquery/misc.d.ts',
86+
]
87+
88+
filesToUncomment.forEach((file) => {
89+
const filePath = join(__dirname, '../types', file)
90+
const str = fs.readFileSync(filePath).toString()
91+
92+
const result = str.split('\n').map((line) => line.substring(3)).join('\n')
93+
94+
fs.writeFileSync(filePath, result)
95+
})

cli/types/cy-bluebird.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Shim definition to export a namespace. Cypress is actually a global module
22
// so import/export isn't allowed there. We import here and define a global module
33
// so that Cypress can get and use the Blob type
4-
import BluebirdStatic = require('./bluebird')
4+
import ImportedBluebird = require('./bluebird')
55

66
export = Bluebird
77
export as namespace Bluebird
88

99
declare namespace Bluebird {
10-
type BluebirdStatic = typeof BluebirdStatic
10+
type BluebirdStatic = typeof ImportedBluebird
11+
interface Promise<T> extends ImportedBluebird<T> {}
1112
}

cli/types/cypress.d.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ declare namespace Cypress {
170170
*/
171171
interface ApplicationWindow { } // tslint:disable-line
172172

173+
/**
174+
* The configuration for Cypress.
175+
*/
176+
type Config = ResolvedConfigOptions & RuntimeConfigOptions
177+
173178
/**
174179
* Several libraries are bundled with Cypress by default.
175180
*
@@ -297,7 +302,7 @@ declare namespace Cypress {
297302
/**
298303
* Fire automation:request event for internal use.
299304
*/
300-
automation(eventName: string, ...args: any[]): Promise<any>
305+
automation(eventName: string, ...args: any[]): Bluebird.Promise<any>
301306

302307
/**
303308
* Promise wrapper for certain internal tasks.
@@ -313,7 +318,7 @@ declare namespace Cypress {
313318
// {defaultCommandTimeout: 10000, pageLoadTimeout: 30000, ...}
314319
```
315320
*/
316-
config(): ResolvedConfigOptions & RuntimeConfigOptions
321+
config(): Config
317322
/**
318323
* Returns one configuration value.
319324
* @see https://on.cypress.io/config

npm/create-cypress-tests/src/component-testing/babel/babelTransform.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference path="../../../../../cli/types/mocha/index.d.ts" />
2+
13
import * as babel from '@babel/core'
24
import { expect } from 'chai'
35
import { createTransformPluginsFileBabelPlugin } from './babelTransform'

npm/cypress-schematic/src/schematics/ng-add/index.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference path="../../../../../cli/types/mocha/index.d.ts" />
2+
13
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'
24
import { join, resolve } from 'path'
35
import { expect } from 'chai'

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"@types/glob": "7.1.1",
9191
"@types/lodash": "4.14.168",
9292
"@types/markdown-it": "0.0.9",
93-
"@types/mini-css-extract-plugin": "1.4.2",
93+
"@types/mini-css-extract-plugin": "1.2.3",
9494
"@types/mocha": "8.0.3",
9595
"@types/node": "14.14.31",
9696
"@types/prismjs": "1.16.0",
@@ -165,7 +165,7 @@
165165
"mock-fs": "4.9.0",
166166
"odiff-bin": "2.1.0",
167167
"parse-github-repo-url": "1.4.1",
168-
"patch-package": "6.2.2",
168+
"patch-package": "6.4.7",
169169
"plist": "3.0.1",
170170
"pluralize": "8.0.0",
171171
"postinstall-postinstall": "2.0.0",
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This file is automatically generated.
2+
// Please do not change this file!
3+
interface CssExports {
4+
5+
}
6+
export const cssExports: CssExports;
7+
export default cssExports;

packages/driver/cypress/integration/dom/visibility_spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-ignore
12
const { $, dom } = Cypress
23

34
describe('src/cypress/dom/visibility', () => {

packages/driver/index.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference path="../../cli/types/index.d.ts" />
2-
/// <reference path="../ts/index.d.ts" />
2+
/// <reference path="../../cli/types/jquery/index.d.ts" />
3+
34
export const $Cypress: Cypress.Cypress
45

5-
export const $: typeof JQuery
6+
export const $: JQuery
67
export default $Cypress

packages/driver/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/// <reference path="../../cli/types/chai-jquery/index.d.ts" />
2+
/// <reference path="../../cli/types/sinon-chai/index.d.ts" />
3+
/// <reference path="../../cli/types/cypress-expect.d.ts" />
4+
5+
/// <reference path="../ts/index.d.ts" />
6+
7+
declare global {
8+
interface Window {
9+
Cypress: Cypress.Cypress
10+
}
11+
}
12+
113
import $Cypress from './src/main'
214

315
export default $Cypress

packages/driver/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
"@sinonjs/fake-timers": "7.0.2",
2727
"@types/chalk": "^2.2.0",
2828
"@types/common-tags": "^1.8.0",
29+
"@types/jquery.scrollto": "1.4.29",
2930
"@types/lodash": "^4.14.168",
3031
"@types/mocha": "^8.0.3",
32+
"@types/underscore.string": "0.0.38",
3133
"angular": "1.8.0",
3234
"basic-auth": "2.0.1",
3335
"blob-util": "2.0.2",

packages/driver/src/config/jquery.scrollto.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @version 2.1.3
99
*/
1010

11+
/// <reference types="jquery.scrollto" />
12+
1113
/** eslint-disable */
1214
import $ from 'jquery'
1315

@@ -109,7 +111,7 @@ export function scrollTo (target, duration, settings) {
109111
let max = $scrollTo.max(elem, axis)
110112

111113
if (toff) { // jQuery / DOMElement
112-
attr[key] = toff[pos] + (win ? 0 : prev - $elem.offset()[pos])
114+
attr[key] = toff[pos] + (win ? 0 : prev - $elem.offset()![pos])
113115

114116
// If it's a dom element, reduce the margin
115117
if (settings.margin) {
@@ -192,18 +194,25 @@ function both (val) {
192194
return isFunction(val) || $.isPlainObject(val) ? val : { top: val, left: val }
193195
}
194196

197+
// TODO: find the type of _last in the JQuery code.
198+
interface Tween extends JQuery.Tween<JQuery.Node> {
199+
_last: any
200+
}
201+
195202
// Add special hooks so that window scroll properties can be animated
196203
$.Tween.propHooks.scrollLeft =
197204
$.Tween.propHooks.scrollTop = {
198205
get (t) {
199206
return $(t.elem)[t.prop]()
200207
},
201-
set (t) {
208+
set (t: Tween) {
202209
let curr = this.get(t)
203210

204211
// If interrupt is true and user scrolled, stop animating
205212
if (t.options.interrupt && t._last && t._last !== curr) {
206-
return $(t.elem).stop()
213+
$(t.elem).stop()
214+
215+
return
207216
}
208217

209218
let next = Math.round(t.now)

packages/driver/src/config/lodash.ts

+9
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ _.mixin({
1010
})
1111

1212
export default _
13+
14+
declare module 'lodash' {
15+
interface LoDashStatic {
16+
clean: typeof clean
17+
count: typeof count
18+
isBlank: typeof isBlank
19+
toBoolean: typeof toBoolean
20+
}
21+
}

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,21 @@ const formatMouseEvents = (events) => {
3333
})
3434
}
3535

36+
// TODO: remove any, Function, Record
37+
type MouseActionOptions = {
38+
subject: any
39+
positionOrX: string | number
40+
y: number
41+
userOptions: Record<string, any>
42+
onReady: Function
43+
onTable: Function
44+
defaultOptions?: Record<string, any>
45+
}
46+
3647
export default (Commands, Cypress, cy, state, config) => {
3748
const { mouse, keyboard } = cy.devices
3849

39-
const mouseAction = (eventName, { subject, positionOrX, y, userOptions, onReady, onTable, defaultOptions }) => {
50+
const mouseAction = (eventName, { subject, positionOrX, y, userOptions, onReady, onTable, defaultOptions }: MouseActionOptions) => {
4051
let position
4152
let x
4253

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import $elements from '../../../dom/elements'
77

88
export default (Commands, Cypress, cy) => {
99
return Commands.addAll({ prevSubject: ['element', 'window'] }, {
10-
focus (subject, options = {}) {
10+
// TODO: any -> Partial<Cypress.Loggable & Cypress.Timeoutable>
11+
focus (subject, options: any = {}) {
1112
const userOptions = options
1213

1314
// we should throw errors by default!
@@ -84,7 +85,8 @@ export default (Commands, Cypress, cy) => {
8485
return verifyAssertions()
8586
},
8687

87-
blur (subject, options = {}) {
88+
// TODO: any -> Partial<Cypress.BlurOptions>
89+
blur (subject, options: any = {}) {
8890
const userOptions = options
8991

9092
// we should throw errors by default!

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

+19-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const isNaNOrInfinity = (item) => {
3030

3131
export default (Commands, Cypress, cy, state) => {
3232
Commands.addAll({ prevSubject: 'element' }, {
33-
scrollIntoView (subject, options = {}) {
33+
// TODO: any -> Partial<Cypress.ScrollToOptions>
34+
scrollIntoView (subject, options: any = {}) {
3435
const userOptions = options
3536

3637
if (!_.isObject(userOptions)) {
@@ -114,6 +115,9 @@ export default (Commands, Cypress, cy, state) => {
114115
const scrollIntoView = () => {
115116
return new Promise((resolve, reject) => {
116117
// 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
117121
return $(options.$parent).scrollTo(options.$el, {
118122
axis: options.axis,
119123
easing: options.easing,
@@ -132,7 +136,7 @@ export default (Commands, Cypress, cy, state) => {
132136
},
133137
always () {
134138
if (parentIsWin) {
135-
return delete options.$parent.contentWindow
139+
delete options.$parent.contentWindow
136140
}
137141
},
138142
})
@@ -153,7 +157,8 @@ export default (Commands, Cypress, cy, state) => {
153157
})
154158

155159
Commands.addAll({ prevSubject: ['optional', 'element', 'window'] }, {
156-
scrollTo (subject, xOrPosition, yOrOptions, options = {}) {
160+
// TODO: any -> Partial<Cypress.ScrollToOptions>
161+
scrollTo (subject, xOrPosition, yOrOptions, options: any = {}) {
157162
let x; let y
158163
let userOptions = options
159164

@@ -168,7 +173,7 @@ export default (Commands, Cypress, cy, state) => {
168173
y = yOrOptions
169174
}
170175

171-
let position = null
176+
let position: string | null = null
172177

173178
// we may be '50%' or 'bottomCenter'
174179
if (_.isString(xOrPosition)) {
@@ -293,7 +298,7 @@ export default (Commands, Cypress, cy, state) => {
293298
$utils.filterOutOptions(options, { duration: 0, easing: 'swing' }),
294299
)
295300

296-
const messageArgs = []
301+
const messageArgs: string[] = []
297302

298303
if (position) {
299304
messageArgs.push(position)
@@ -306,12 +311,12 @@ export default (Commands, Cypress, cy, state) => {
306311
messageArgs.push(deltaOptions)
307312
}
308313

309-
const log = {
314+
const log: Record<string, any> = {
310315
message: messageArgs.join(', '),
311316
timeout: options.timeout,
312317
consoleProps () {
313318
// merge into consoleProps without mutating it
314-
const obj = {}
319+
const obj: Record<string, any> = {}
315320

316321
if (position) {
317322
obj.Position = position
@@ -357,10 +362,16 @@ export default (Commands, Cypress, cy, state) => {
357362
const scrollTo = () => {
358363
return new Promise((resolve, reject) => {
359364
// 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
360368
$(options.$el).scrollTo({ left: x, top: y }, {
361369
axis: options.axis,
362370
easing: options.easing,
363371
duration: options.duration,
372+
// TODO: ensureScrollable option does not exist on jQuery or config/jquery.scrollto.ts.
373+
// It can be removed.
374+
// @ts-ignore
364375
ensureScrollable: options.ensureScrollable,
365376
done () {
366377
return resolve(options.$el)
@@ -376,7 +387,7 @@ export default (Commands, Cypress, cy, state) => {
376387
})
377388

378389
if (isWin) {
379-
return delete options.$el.contentWindow
390+
delete options.$el.contentWindow
380391
}
381392
})
382393
}

0 commit comments

Comments
 (0)