JSMonk / hegel

An advanced static type checker
https://hegel.js.org
MIT License
2.09k stars 59 forks source link

Intersection of generic object types #270

Closed Kapelianovych closed 4 years ago

Kapelianovych commented 4 years ago

Should we be able to create $Intersection of generic object types?

type Functor<T> = {
  map: <R>(fn: (value: T) => R) => Functor<R>
}

type Apply<T> = {
  apply: <R>(apply: Apply<(value: T) => R>) => Apply<R>
}

// Types that implements Applicative must implement Apply
// Here Hegel show an error: All parameters should be an object type. Only first parameter should mutable object type. 0 is not.
type Applicative<T> = $Intersection<Apply<T>, { of: (value: T) => Applicative<T> }>

// Here Hegel show an error: All parameters should be an object type. Only first parameter should mutable object type. 0 is not.
type Monad<T> = $Intersection<Applicative<T>, Functor<T>>
JSMonk commented 4 years ago

Fixed in 0.0.44