flowtype - Maybe-type of generic type parameter is incompatible with empty -


for every instantiation of remoteentity, error on type parameter this type incompatible empty, referencing null value value in newremoteentity:

export type remoteentity<t: identifiable> = {   value: ?t;   error: ?error;   // ... }  export function newremoteentity(): remoteentity<*> {   return {     value: null, // error     error: null, // ok     // ...   } } 

if instead declare value: ?object, these errors go away (but other errors related loss of type bound). missing or flowtype bug/quirk?

i found workaround making fields optional (instead of required maybe-type). however, makes other code little more complicated (since have check nulls instead of propagating them in object literals), prefer having maybe-types work.

export type remoteentity<t: identifiable> = {   value?: t;   error?: error;   pendingaction: ?string;   // ... }  export function newremoteentity(): remoteentity<*> {   return {     pendingaction: null,     // ...   } }  export function requested<t: identifiable>(     state: remoteentity<t>, action: string, id?: string): remoteentity<t> {   // maybe-type version more concise:   // return {   //   state: id && state.value && state.value.id === id ? state.value : null,   //   error: null,   //   pendingaction: action,   //   // ...   // }   const result: remoteentity<t> = {     pendingaction: action,     // ...   }   if (id && state.value && state.value.id === id) {     result.value = state.value   }   return result } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -