re: Flow 0.99: Callable Properties, Function Statics, and More VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hey, Yawar, thank you for bringing this up! It just so happened that I'm recently stuck with this because we changed a shared type from interface t...
 

Hey in this case it seems a disjoint union would work, e.g.

type PureTOrGenT<T> =
  | {tag: 'PureT', value: T}
  | {tag: 'GenT', value: () => T}

function logMyCorn<Unicorn>(unicorn: PureTOrGenT<Unicorn>) {
  switch (unicorn.tag) {
    case 'PureT':
      console.log(unicorn.value)
      break
    case 'GenT':
      console.log(unicorn.value())
  }
}

The tag allows Flow to refine the type of value down to a T or exact function type in each branch.

My rule of thumb is to stick to interfaces unless I need the added power of unions, intersections, exact types etc. However I'm not sure what could be causing the first error you mentioned, because interfaces and inexact object types are equivalent afaik. I'll need to investigate further.

code of conduct - report abuse