Created
September 21, 2018 16:17
-
-
Save Quramy/f9411359cdd18f269d27501d41271065 to your computer and use it in GitHub Desktop.
Example of TS 3.1 Mapped Tuple Type
This file contains 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 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