From 3ba1e8baeae49c28daec43e6ad3ee31b3079872b Mon Sep 17 00:00:00 2001 From: Robbie Coomber Date: Fri, 3 Nov 2023 10:54:25 +0000 Subject: [PATCH] TypeScript magic --- src/utils/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index 326167570..e590f05b0 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -202,11 +202,14 @@ export const _safewrap_instance_methods = function (obj: Record): v } } -export const _strip_empty_properties = function >(p: T): { [k in keyof T]?: T[k] } { - const ret: Partial = {} +export const _strip_empty_properties = function >( + 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