@@ -44,7 +44,7 @@ const hasGetterFromConstructor = (object: object, key: string) => {
44
44
return descriptor !== undefined && typeof descriptor . get === 'function' ;
45
45
} ;
46
46
47
- export const hasOwnProperty = ( object : object , key : string ) =>
47
+ export const hasOwnProperty = ( object : object , key : string ) : boolean =>
48
48
Object . prototype . hasOwnProperty . call ( object , key ) ||
49
49
hasGetterFromConstructor ( object , key ) ;
50
50
@@ -104,6 +104,7 @@ export const getPath = (
104
104
105
105
// Strip properties from object that are not present in the subset. Useful for
106
106
// printing the diff for toMatchObject() without adding unrelated noise.
107
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
107
108
export const getObjectSubset = (
108
109
object : any ,
109
110
subset : any ,
@@ -147,12 +148,13 @@ const IteratorSymbol = Symbol.iterator;
147
148
const hasIterator = ( object : any ) =>
148
149
! ! ( object != null && object [ IteratorSymbol ] ) ;
149
150
151
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
150
152
export const iterableEquality = (
151
153
a : any ,
152
154
b : any ,
153
155
aStack : Array < any > = [ ] ,
154
156
bStack : Array < any > = [ ] ,
155
- ) => {
157
+ ) : boolean | undefined => {
156
158
if (
157
159
typeof a !== 'object' ||
158
160
typeof b !== 'object' ||
@@ -273,16 +275,17 @@ const isObjectWithKeys = (a: any) =>
273
275
! ( a instanceof Array ) &&
274
276
! ( a instanceof Date ) ;
275
277
278
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
276
279
export const subsetEquality = (
277
280
object : any ,
278
281
subset : any ,
279
- ) : undefined | boolean => {
282
+ ) : boolean | undefined => {
280
283
// subsetEquality needs to keep track of the references
281
284
// it has already visited to avoid infinite loops in case
282
285
// there are circular references in the subset passed to it.
283
286
const subsetEqualityWithContext = (
284
287
seenReferences : WeakMap < object , boolean > = new WeakMap ( ) ,
285
- ) => ( object : any , subset : any ) : undefined | boolean => {
288
+ ) => ( object : any , subset : any ) : boolean | undefined => {
286
289
if ( ! isObjectWithKeys ( subset ) ) {
287
290
return undefined ;
288
291
}
@@ -314,15 +317,19 @@ export const subsetEquality = (
314
317
return subsetEqualityWithContext ( ) ( object , subset ) ;
315
318
} ;
316
319
317
- export const typeEquality = ( a : any , b : any ) => {
320
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
321
+ export const typeEquality = ( a : any , b : any ) : boolean | undefined => {
318
322
if ( a == null || b == null || a . constructor === b . constructor ) {
319
323
return undefined ;
320
324
}
321
325
322
326
return false ;
323
327
} ;
324
328
325
- export const sparseArrayEquality = ( a : unknown , b : unknown ) => {
329
+ export const sparseArrayEquality = (
330
+ a : unknown ,
331
+ b : unknown ,
332
+ ) : boolean | undefined => {
326
333
if ( ! Array . isArray ( a ) || ! Array . isArray ( b ) ) {
327
334
return undefined ;
328
335
}
@@ -347,7 +354,7 @@ export const partition = <T>(
347
354
} ;
348
355
349
356
// Copied from https://github.com/graingert/angular.js/blob/a43574052e9775cbc1d7dd8a086752c979b0f020/src/Angular.js#L685-L693
350
- export const isError = ( value : unknown ) => {
357
+ export const isError = ( value : unknown ) : value is Error => {
351
358
switch ( Object . prototype . toString . call ( value ) ) {
352
359
case '[object Error]' :
353
360
return true ;
@@ -360,13 +367,14 @@ export const isError = (value: unknown) => {
360
367
}
361
368
} ;
362
369
363
- export function emptyObject ( obj : any ) {
370
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
371
+ export function emptyObject ( obj : any ) : boolean {
364
372
return obj && typeof obj === 'object' ? ! Object . keys ( obj ) . length : false ;
365
373
}
366
374
367
375
const MULTILINE_REGEXP = / [ \r \n ] / ;
368
376
369
- export const isOneline = ( expected : any , received : any ) : boolean =>
377
+ export const isOneline = ( expected : unknown , received : unknown ) : boolean =>
370
378
typeof expected === 'string' &&
371
379
typeof received === 'string' &&
372
380
( ! MULTILINE_REGEXP . test ( expected ) || ! MULTILINE_REGEXP . test ( received ) ) ;
0 commit comments