Reputation: 923
I would like to have an type for my observable (just for learning purposes). How can I do it for the follwoing lines of code? I get compiler errors and don't understand them.
type Color = "white" | "green" | "red" | "blue";
type Logo = "fish" | "dog" | "bird" | "cow";
const color$ = new Subject<Color>();
const logo$ = new Subject<Logo>();
const observabl1:<Subject<Color>, Subject<Logo>> = combineLatest([color$, logo$]);
observabl1.subscribe(([color, logo]) =>
console.log(`${color} ${logo}`)
);
and
const observable2$:Observable<string> = from(["white", "green", "red", "blue"]);
Update: I found the error. I imported import { Observable } from 'rx'; Changing it to import { Observable } from 'rxjs'; fixed the problem
Upvotes: 0
Views: 30
Reputation: 9124
I get compiler errors and don't understand them
Kindly provide the errors you want to discuss.
const observabl1:<Subject, Subject> = combineLatest([color$, logo$]);
combineLatest provides a stream with an array of the data.
const observabl1: Observable<[Color, logo]> = combineLatest([color$, logo$]);
Upvotes: 1