Composable and positive contracts in Flow


April 2019


6 time


I'm having a problem with Flow where a given implemented type is restricting my object API by asking me to use only properties that are declared on the type instead of asking me to declare all the type's properties.

I'm new to Flow so I'm probably making some basic mistake and stuff. Anyway, I have this type declared:

type Unit = {
  of(value: any): Monad,

What I'm trying to do here is to say: all objects implemented according to Unit must have an #of method that receives a given value and returns a Monad-type value.

When I implemented it on my factory no problem came up:

const Maybe: Unit = {
    isMaybe: (obj): boolean => { ... },
    of: (value): Monad => { ... },


But when I try to call #isMaybe, I get this error (on the linter):

flow(0|2), isMaybe (Cannot call: `Maybe.isMaybe` because property `isMaybe` is missing in `Unit` [1].)

Now I tried declaring #isMaybe on Unit and the error disappeared as expected. Problem is, Unit should be a kind of liberal that interface checks if it's implementations have Unit properties instead of only Unit properties.

I can't refactor - at least not that I know - Unit from a type to a interface because I'm composing them through is-a relationships:

type Monad = Applicative & Chain; // Monad is-a Applicative and a Chain

Is there any way to make a contract both positive and composable with Flow?

0 answers