Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinctiveness of MemoryStream and Stream #306

Open
wclr opened this issue Jul 1, 2020 · 1 comment
Open

Distinctiveness of MemoryStream and Stream #306

wclr opened this issue Jul 1, 2020 · 1 comment

Comments

@wclr
Copy link
Contributor

wclr commented Jul 1, 2020

Currently, MemoryStream and Stream has exactly the same API surface. Though MemoryStream is actually a descendant from Stream which is a more abstract case.

So, now:

// those are both valid cases
const stream: Stream<any> = xs.createWithMemory() // is valid
const memoryStream: MemoryStream<any> = xs.create() // is valid

Though it seems that the latter case would better be invalid in terms of type checking. If you expect MemoryStream you probably should not expect or want just Stream as an input.

Currently, I fix this:

declare module 'xstream' {
  interface MemoryStream<T> {
    // make MemoryStream distinctive from Stream
    __withMemory: true // this could be any prop, here
  }

But such distinction could be introduced in xstream by design. Maybe this issue could also relate to #304 which is runtime case for finding a distinction between types of streams.

@mightyiam
Copy link
Contributor

@whitecolor by the way, perhaps distinctiveness could be more reliable using a symbol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants