mirror of https://github.com/nocodb/nocodb
DarkPhoenix2704
4 months ago
3 changed files with 16 additions and 99 deletions
@ -1,26 +0,0 @@
|
||||
type NonUndefined<T> = T extends undefined ? never : T |
||||
type NonNull<T> = T extends null ? never : T |
||||
type NonNullableObject<T> = { |
||||
[K in keyof T]: NonUndefined<NonNull<T[K]>> |
||||
} |
||||
|
||||
type Prettify<T> = { |
||||
[K in keyof T]: T[K] |
||||
} & {} |
||||
|
||||
export const stripUndefinedOrNull = <T>(obj: T): Prettify<NonNullableObject<T>> => { |
||||
const strip = (input: unknown): unknown => { |
||||
return Array.isArray(input) |
||||
? input.map(strip) |
||||
: input !== null && typeof input === 'object' |
||||
? Object.entries(input) |
||||
.filter(([, value]) => value !== undefined && value !== null) |
||||
.reduce((acc, [key, value]) => { |
||||
acc[key as keyof typeof acc] = strip(value) |
||||
return acc |
||||
}, {} as Record<string, unknown>) |
||||
: input |
||||
} |
||||
|
||||
return strip(obj) as Prettify<NonNullableObject<T>> |
||||
} |
Loading…
Reference in new issue