

export function filterNullKeysOfObject<T extends object>(object: T): T {
    if (typeof object !== "object") {
        return object
    }
    return Object.keys(object)
        .filter(key => {
            if (typeof object[key as keyof T] === "object" && object[key as keyof T] !== null) {
                return Object.keys(object[key as keyof T] as object).length
            }
            if (typeof object[key as keyof T] === "string") {
                return !!(object[key as keyof T] as string).length
            }
            return object[key as keyof T] !== null
        })
        .reduce((acc, key) => {
            return Object.assign(acc, {
                [key]: typeof object[key as keyof T] === "object" ? filterNullKeysOfObject<typeof object>(object[key as keyof object]) : object[key as keyof T]
            });
        }, Array.isArray(object) ? [] : {}) as T;
}