Open Gozala opened 7 years ago
To be more clear this is a behavior I'm aiming for:
/* @flow */
class Task <x, a> {
static succeed: <x, a> (value:a) => Task<x, a>
static fail: <x, a> (error:x) => Task<x, a>
static spawn: <a, b> (task:Task<empty, a>) => Task<empty, b>
}
Task.spawn(Task.succeed(4))
Task.spawn(Task.fail(4))
Which fails if failing task is spawn, but does not fail if succeeding task is spawn:
10: Task.spawn(Task.fail(4))
^ number. This type is incompatible with
6: static spawn: <a, b> (task:Task<empty, a>) => Task<empty, b>
^ empty
I just want to enable calling spawn
as a method rather than static function.
Here is simplified example:
Here flow reports following error:
What I actually expect is for flow to report type error when
task.spawn()
is called on tasks that can fail (Task<error, value>
) and report no errors when called on tasks that can not fail (Task<empty, value>
).