Skip to content

Instantly share code, notes, and snippets.

@sallar
Created November 20, 2017 08:40
Show Gist options
  • Save sallar/ae15ae794e58af55c7a87bacd2102c07 to your computer and use it in GitHub Desktop.
Save sallar/ae15ae794e58af55c7a87bacd2102c07 to your computer and use it in GitHub Desktop.
Typescript Module Curry
module Cart {
export function test1() {
console.log('hi');
}
export function test2() { }
}
function curryModule<T>(mod: T): T {
return Object
.keys(mod)
.map(method => ({ method, fn: mod[method] }))
.reduce((all: T, curr) => {
all[curr.method] = curr.fn;
return all;
}, {} as T);
}
curryModule(Cart).test1();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment