11import { isEqual , mapValues , union } from 'lodash'
22
3- type RemoveUndefined < T extends object > = {
4- [ K in keyof T as T [ K ] extends undefined ? never : K ] : Exclude < T [ K ] , undefined >
5- }
6-
73export const removeUndefinedProps = < T extends object > (
84 obj : T ,
9- ) : RemoveUndefined < T > => {
10- const newObj : Record < string , unknown > = { }
5+ ) : {
6+ [ K in keyof T as T [ K ] extends undefined ? never : K ] : Exclude < T [ K ] , undefined >
7+ } => {
8+ const newObj : any = { }
119
1210 for ( const key of Object . keys ( obj ) ) {
13- const value = obj [ key as keyof T ]
14- if ( value !== undefined ) newObj [ key ] = value
11+ if ( ( obj as any ) [ key ] !== undefined ) newObj [ key ] = ( obj as any ) [ key ]
1512 }
1613
17- return newObj as RemoveUndefined < T >
14+ return newObj
1815}
1916
2017export const removeNullOrUndefinedProps = < T extends object > (
2118 obj : T ,
2219 exceptions ?: string [ ] ,
2320) : T => {
24- const newObj : Record < string , unknown > = { }
21+ const newObj : any = { }
2522
2623 for ( const key of Object . keys ( obj ) ) {
27- const value = obj [ key as keyof T ]
2824 if (
29- ( value !== undefined && value !== null ) ||
25+ ( ( obj as any ) [ key ] !== undefined && ( obj as any ) [ key ] !== null ) ||
3026 ( exceptions ?? [ ] ) . includes ( key )
3127 )
32- newObj [ key ] = value
28+ newObj [ key ] = ( obj as any ) [ key ]
3329 }
34- return newObj as T
30+ return newObj
3531}
3632
3733export const addObjects = < T extends { [ key : string ] : number } > (
3834 obj1 : T ,
3935 obj2 : T ,
4036) => {
4137 const keys = union ( Object . keys ( obj1 ) , Object . keys ( obj2 ) )
42- const newObj : Record < string , number > = { }
38+ const newObj = { } as any
4339
4440 for ( const key of keys ) {
4541 newObj [ key ] = ( obj1 [ key ] ?? 0 ) + ( obj2 [ key ] ?? 0 )
@@ -53,7 +49,7 @@ export const subtractObjects = <T extends { [key: string]: number }>(
5349 obj2 : T ,
5450) => {
5551 const keys = union ( Object . keys ( obj1 ) , Object . keys ( obj2 ) )
56- const newObj : Record < string , number > = { }
52+ const newObj = { } as any
5753
5854 for ( const key of keys ) {
5955 newObj [ key ] = ( obj1 [ key ] ?? 0 ) - ( obj2 [ key ] ?? 0 )
@@ -72,19 +68,14 @@ export const hasSignificantDeepChanges = <T extends object>(
7268 partial : Partial < T > ,
7369 epsilonForNumbers : number ,
7470) : boolean => {
75- const compareValues = ( currValue : unknown , partialValue : unknown ) : boolean => {
71+ const compareValues = ( currValue : any , partialValue : any ) : boolean => {
7672 if ( typeof currValue === 'number' && typeof partialValue === 'number' ) {
7773 return Math . abs ( currValue - partialValue ) > epsilonForNumbers
7874 }
79- if (
80- typeof currValue === 'object' &&
81- currValue !== null &&
82- typeof partialValue === 'object' &&
83- partialValue !== null
84- ) {
75+ if ( typeof currValue === 'object' && typeof partialValue === 'object' ) {
8576 return hasSignificantDeepChanges (
86- currValue as Record < string , unknown > ,
87- partialValue as Partial < Record < string , unknown > > ,
77+ currValue ,
78+ partialValue ,
8879 epsilonForNumbers ,
8980 )
9081 }
@@ -104,7 +95,7 @@ export const hasSignificantDeepChanges = <T extends object>(
10495
10596export const filterObject = < T extends object > (
10697 obj : T ,
107- predicate : ( value : T [ keyof T ] , key : keyof T ) => boolean ,
98+ predicate : ( value : any , key : keyof T ) => boolean ,
10899) : { [ P in keyof T ] : T [ P ] } => {
109100 const result = { } as { [ P in keyof T ] : T [ P ] }
110101 for ( const key in obj ) {
0 commit comments