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

Stricter types? #64

Open
tim-smart opened this issue Mar 17, 2022 · 1 comment
Open

Stricter types? #64

tim-smart opened this issue Mar 17, 2022 · 1 comment

Comments

@tim-smart
Copy link

Would the Typescript community benefit from stricter types?
It saves a few headaches when your compiler can hold your hand a bit more :)

A few things I would be looking for:

  • Allow the error type to be specified
  • Stricter signal / parameters for each type of callbag

Here is something I have been using:

export enum Signal {
  START = 0,
  DATA = 1,
  END = 2,
}

export type TalkbackArgs = [signal: Signal.DATA] | [signal: Signal.END]
export type Talkback = (...op: TalkbackArgs) => void

export type SinkArgs<E, A> =
  | [signal: Signal.START, talkback: Talkback]
  | [signal: Signal.DATA, data: A]
  | [signal: Signal.END, error?: E]
export type Sink<E, A> = (...op: SinkArgs<E, A>) => void

export type SourceArgs<E, A> = [signal: Signal.START, sink: Sink<E, A>]
export type Source<E, A> = (...op: SourceArgs<E, A>) => void

export type Callbag<E, A> = Source<E, A> | Sink<E, A>
@tim-smart
Copy link
Author

Quick update, created a small package for this: https://github.com/tim-smart/strict-callbag

I also added an error type to the talkback arguments, as often a sink can fail with an error (writing a file to disk can fail etc)

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

1 participant