[Typescript] [RxJS] Why is there no type error when returning an observable partial type?
For a type variable, Observable<T>
I tried to assign Observable<S>
where S
is part T
and am surprised that there is no assignment error at compile time.
I would like to take the brains to understand the reason for this behavior.
// RxJS 5.3.0
// TS 2.2.2
interface Super {
a: number;
b: number;
}
interface Subset {
a: number;
}
type Maybe<T> = T | undefined;
// Both of the following produce errors
const super1: Super = {a: 1} as Subset;
const superMaybe: Maybe<Super> = { a: 1 } as Maybe<Subset>;
// But this doesn't error
const superObservable: Rx.Observable<Super> = Rx.Observable.of<Subset>({a: 1});
+3
source to share