Open wessberg opened 8 years ago
I'm looking for a bound on T that would let me use this min
function with Date
objects. Am I currently out of luck?
// ack: Linus Unnebäck Nov 18 '12
// http://stackoverflow.com/a/13440842
function min/*:: <T>*/(arr /*: Array<T>*/) {
return arr.reduce((p, v) => p < v ? p : v );
}
Consider this:
The
valueOf()
method gets special treatment in Javascript and returns the primitive value for an Object type.It can be implemented by any object so that they can be used in comparisons with the '<', '==', '===' and '>' operators. However, from the example above it appears to be the case that flow doesn't understand that the
valueOf()
method in theComparable
interface can be used without callingfirst.valueOf() > second.valueOf()
directly.I'd love to see this implemented in flow. It will be nice if flow throws the error only if the given item is an object type and doesn't implement
valueOf()
.