Skip to content

Instantly share code, notes, and snippets.

@babakness
Created October 4, 2018 03:32
Show Gist options
  • Save babakness/9deb5eb317fc4436eecc4c39b3e8cbae to your computer and use it in GitHub Desktop.
Save babakness/9deb5eb317fc4436eecc4c39b3e8cbae to your computer and use it in GitHub Desktop.
Sample pipe function using overloads in TypeScript
// Example taken from @type/ramda at the time of this writing.
pipe<T1>(fn0: () => T1): () => T1;
pipe<V0, T1>(fn0: (x0: V0) => T1): (x0: V0) => T1;
pipe<V0, V1, T1>(fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T1;
pipe<V0, V1, V2, T1>(fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T1;
pipe<T1, T2>(fn0: () => T1, fn1: (x: T1) => T2): () => T2;
pipe<V0, T1, T2>(fn0: (x0: V0) => T1, fn1: (x: T1) => T2): (x0: V0) => T2;
pipe<V0, V1, T1, T2>(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2): (x0: V0, x1: V1) => T2;
pipe<V0, V1, V2, T1, T2>(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2): (x0: V0, x1: V1, x2: V2) => T2;
//.. and so on...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment