Skip to content

Instantly share code, notes, and snippets.

@nmn
nmn / FunctionValue.ts
Last active November 3, 2017 12:25
Magic Flow Type 1: $FunctionXValue —— A magic flow type that takes a function type that takes one arg, the type of that arg, and returns the return value type of the function.
/* @flow */
type $Function1<A, B> = (arg: A) => B;
type _Function1Value<A, B, F: $Function1<A, B>> = B; // eslint-disable-line
type $Function1Value<F: $Function1<*, *>, A> = _Function1Value<A, *, F>;
var toString = (value) => String(value)
var toNumber = (value) => parseFloat(value) || 0
type NumberXString = ((value: number) => string) & ((value: string) => number)