Open olehmisar opened 1 year ago
This is an implementation detail for rxjs interop, but I'm not sure we want to expose it publicly. If you have a rxjs observable, why would you want to use it with derived
anyway? Can't use you .pipe
and the rxjs operators for that?
I want to mix svelte stores with rx observables
Your request is legit, however the severity is so over-stated. I can easily fix it with @ts-ignore
and move on. Please report severity properly.
I've taken to using these two helpers in order to get interop:
export function store_to_observable<T>(store: Writable<T> | Readable<T>): Observable<T> {
return new Observable<T>((observer) => {
return store.subscribe((value) => observer.next(value));
});
}
export function observable_to_store<T>(observable: Observable<T>): Writable<T> {
const store = writable<T>();
observable.subscribe((value) => store.set(value));
return store;
}
But it sound to me like doing this is perfectly safe:
export function observable_to_store<T>(observable: Observable<T>): Writable<T> {
return observable as any as Writable<T>;
}
Is this correct?
Describe the bug
I cannot use an
rxjs.Observable
withderived
because svelte'sUnsubscriber
is not typed properly: https://github.com/sveltejs/svelte/blob/3bc791bcba97f0810165c7a2e215563993a0989b/src/runtime/store/index.ts#L6-L7It should be typed as
Reproduction
Logs
No response
System Info
Severity
annoyance