Skip to content

vueuse/rxjs useObservable usage with nested objects/observables #1416

Answered by scvnc
abarke asked this question in Q&A
Discussion options

You must be logged in to vote

Why I think this surrounds a bug

At a glance, this is a bug in the type signature of useObservable. The type signature says that it returns Ref<H> but per your example it obviously returns Ref<H | undefined>.

Interestingly enough, this seems to be the case becuase the next line declares a ref of the correct type but by the time it is returned, it incorrectly casts away.

How is this solved in other ecosystems (Flutter)

In Dart, where Streams are first class, the authors of the Flutter equivalent of VueUse allow you to provide an initialData

const count = useObservable(myCount$, {initialData: 0})

This ensures that it always returns a Ref<number> otherwise it returns Ref<number | undefined>

A…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@abarke
Comment options

@scvnc
Comment options

@scvnc
Comment options

@scvnc
Comment options

@abarke
Comment options

Answer selected by okxiaoliang4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants