Skip to content

Commit

Permalink
TypeScript magic
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Nov 3, 2023
1 parent 4341121 commit 4c3235a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,14 @@ export const _safewrap_instance_methods = function (obj: Record<string, any>): v
}
}

export const _strip_empty_properties = function <T extends Record<string, any>>(p: T): { [k in keyof T]?: T[k] } {
const ret: Partial<T> = {}
export const _strip_empty_properties = function <T extends Record<string, any>>(
p: T
): // remove non-string properties from the type and all keys optional
{ [k in keyof T as T[k] extends string ? k : never]?: T[k] } {
const ret = {} as any
_each(p, function (v, k) {
if (_isString(v) && v.length > 0) {
;(ret as any)[k] = v
ret[k] = v
}
})
return ret
Expand Down

0 comments on commit 4c3235a

Please sign in to comment.