0no-co / wonka

🎩 A tiny but capable push & pull stream library for TypeScript and Flow
MIT License
709 stars 29 forks source link

`Wonka.share` type contains type variables that can't be generalized: Wonka_types.sourceT('_weak1) #104

Closed idkjs closed 3 years ago

idkjs commented 3 years ago

Running the docs example, I get:

let source = Wonka.never
  |> Wonka.onStart((. ) => print_endline("start"))
  |> Wonka.share;

Wonka.publish(source);
Wonka.publish(source);

Output

 let source = Wonka.never
  21 │   |> Wonka.onStart((. ) => print_endline("start"))
  22 │   |> Wonka.share;

  This expression's type contains type variables that can't be generalized:
  Wonka_types.sourceT('_weak1)

  This happens when the type system senses there's a mutation/side-effect,
  in combination with a polymorphic value.
  Using or annotating that value usually solves it.

FAILED: cannot make progress due to previous errors.
>>>> Finish compiling(exit: 1)

How would you annotate this function to get it to work? Thank you!

kitten commented 3 years ago

This has no type that can be used to fill out the missing type of the source, hence it'll need to be recast or used in a way that gives the stream a type