import { expectType, Optional } from 'ts-data-forge'; import { type AsyncChildObservable, type ChildObservable, type Observable, type ObservableBase, type RootObservable, type SyncChildObservable, } from '../types/index.mjs'; import { AsyncChildObservableClass, SyncChildObservableClass, } from './child-observable-class.mjs'; import { RootObservableClass } from './root-observable-class.mjs'; /** * Inheritance * * ```txt * ObservableBase * | * +- SyncChildObservable \ \ * | +-- ChildObservable \ * +- AsyncChildObservable X +-- Observable * | +-- ManagerObservable / * +- RootObservableType / / * ``` */ // type tests expectType, Observable>('='); expectType, Observable>('!<='); // inheritance expectType, ObservableBase>('<='); expectType, ChildObservable>('<='); expectType, ChildObservable>('<='); expectType, ObservableBase>('<='); expectType, ChildObservable>('<='); expectType, ObservableBase>('<='); expectType, Observable>('!<='); expectType, Observable>('<='); // ObservableBase is covariant expectType, ObservableBase>('<='); expectType, ObservableBase<1>>('!<='); // Observable is covariant expectType, Observable>('<='); expectType, Observable<1>>('!<='); const root = new RootObservableClass({ initialValue: Optional.some(0), }); expectType>('<='); const syncChild = new SyncChildObservableClass({ parents: [root], initialValue: Optional.some(0), }); expectType>('<='); const asyncChild = new AsyncChildObservableClass({ parents: [root], initialValue: Optional.some(0), }); expectType>('<='); test('SyncChildObservableClass', () => { expect(syncChild.depth).toBe(1); }); test('AsyncChildObservableClass', () => { expect(asyncChild.depth).toBe(1); });