Tuesday 26 February 2019

Under @flow strict, what alternatives are there to Object for utility functions?

I am interested in switching my Flow code to strict type checking, but I have some low-level utility functions that deal with Objects generically, such as:

// @flow strict

const hasKey = (o: Object): (string => boolean) =>
  Object.prototype.hasOwnProperty.bind(o);

const union = (os: Array<Object>): Object =>
  os.reduceRight((acc, o) => ({ ...acc, ...o }), {});

Since the Object type isn't allowed in strict mode, how do you declare types for functions that are explicitly supposed to operate on any generic Object?



from Under @flow strict, what alternatives are there to Object for utility functions?

No comments:

Post a Comment