Skip to content

Instantly share code, notes, and snippets.

@Quramy
Created September 21, 2018 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quramy/f9411359cdd18f269d27501d41271065 to your computer and use it in GitHub Desktop.
Save Quramy/f9411359cdd18f269d27501d41271065 to your computer and use it in GitHub Desktop.
Example of TS 3.1 Mapped Tuple Type
interface Observable<T> {
subscribe(cb: (v: T) => void): void;
}
type StreamValue<S> = S extends Observable<infer T> ? T : never;
type Unwrap<S> = { [P in keyof S]: StreamValue<S[P]> };
declare function combineLatest<U extends Observable<any>[]>(...streams: U): Observable<Unwrap<U>>;
function test(s1$: Observable<string>, s2$: Observable<number>, s3$: Observable<string>) {
combineLatest(s1$, s2$).subscribe(([s1, s2]) => console.log(s1, s2));
combineLatest(s1$, s2$, s3$).subscribe(([s1, s2, s3]) => console.log(s1, s2, s3));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment