Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save forksofpower/3890aab28645b75e58b487568e5f341a to your computer and use it in GitHub Desktop.
Save forksofpower/3890aab28645b75e58b487568e5f341a to your computer and use it in GitHub Desktop.
Load objects from module import
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