Created
June 26, 2021 23:07
-
-
Save forksofpower/3890aab28645b75e58b487568e5f341a to your computer and use it in GitHub Desktop.
Load objects from module import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ObjectConstructor { | |
keys<T>(o: T): ObjectKeys<T>; | |
} | |
function reduce<TElement, TResult>( | |
array: TElement[], | |
reducer: (result: TResult, el: TElement) => TResult, | |
initialResult: TResult | |
): TResult { | |
let result = initialResult; | |
for (const element of array) { | |
result = reducer(result, element); | |
} | |
return result; | |
} | |
function reduceStringArray<TResult>( | |
array: string[], | |
reducer: (result: TResult, el: string) => TResult, | |
initialResult: TResult | |
): TResult { | |
let result = initialResult; | |
for (const element of array) { | |
result = reducer(result, element); | |
} | |
return result; | |
} | |
// type aliasKeys = (obj: string) => void; | |
// type PropType<TObj, TProp extends keyof TObj> = TObj[TProp]; | |
const aliasObjectKeys = <TPropType, TResult = { [x: string]: TPropType }>( | |
obj: TResult | |
): TResult => | |
reduceStringArray<TResult>( | |
Object.keys(obj) as string[], | |
(result, el) => { | |
if () | |
return { ...result, [(obj as TResult)[el].key]: obj[el] }; | |
}, | |
{} as TResult | |
); | |
const LoadResourceKeys = (obj: ResourcesSchema): ResourcesSchema => | |
aliasObjectKeys<ZapierResource, ResourcesSchema>(obj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment