@@ -5,6 +5,7 @@ import Promise from 'bluebird'
5
5
import $dom from '../../../dom'
6
6
import $utils from '../../../cypress/utils'
7
7
import $errUtils from '../../../cypress/error_utils'
8
+ import type { Log } from '../../../cypress/log'
8
9
9
10
const findScrollableParent = ( $el , win ) => {
10
11
const $parent = $dom . getParent ( $el )
@@ -28,12 +29,26 @@ const isNaNOrInfinity = (item) => {
28
29
return _ . isNaN ( num ) || ! _ . isFinite ( num )
29
30
}
30
31
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
+
31
49
export default ( Commands , Cypress , cy , state ) => {
32
50
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 > = { } ) {
37
52
if ( ! _ . isObject ( userOptions ) ) {
38
53
$errUtils . throwErrByPath ( 'scrollIntoView.invalid_argument' , { args : { arg : userOptions } } )
39
54
}
@@ -49,7 +64,7 @@ export default (Commands, Cypress, cy, state) => {
49
64
$errUtils . throwErrByPath ( 'scrollIntoView.multiple_elements' , { args : { num : subject . length } } )
50
65
}
51
66
52
- options = _ . defaults ( { } , userOptions , {
67
+ const options : InternalScrollIntoViewOptions = _ . defaults ( { } , userOptions , {
53
68
$el : subject ,
54
69
$parent : state ( 'window' ) ,
55
70
log : true ,
@@ -115,9 +130,6 @@ export default (Commands, Cypress, cy, state) => {
115
130
const scrollIntoView = ( ) => {
116
131
return new Promise ( ( resolve , reject ) => {
117
132
// 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
121
133
return $ ( options . $parent ) . scrollTo ( options . $el , {
122
134
axis : options . axis ,
123
135
easing : options . easing ,
@@ -157,10 +169,8 @@ export default (Commands, Cypress, cy, state) => {
157
169
} )
158
170
159
171
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 > = { } ) {
162
173
let x ; let y
163
- let userOptions = options
164
174
165
175
// check for undefined or null values
166
176
if ( xOrPosition === undefined || xOrPosition === null ) {
@@ -261,7 +271,7 @@ export default (Commands, Cypress, cy, state) => {
261
271
$errUtils . throwErrByPath ( 'scrollTo.multiple_containers' , { args : { num : $container . length } } )
262
272
}
263
273
264
- options = _ . defaults ( { } , userOptions , {
274
+ const options : InternalScrollToOptions = _ . defaults ( { } , userOptions , {
265
275
$el : $container ,
266
276
log : true ,
267
277
duration : 0 ,
@@ -361,10 +371,7 @@ export default (Commands, Cypress, cy, state) => {
361
371
362
372
const scrollTo = ( ) => {
363
373
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
368
375
$ ( options . $el ) . scrollTo ( { left : x , top : y } , {
369
376
axis : options . axis ,
370
377
easing : options . easing ,
0 commit comments