I'm doing some work on iflow-lodash which doesn't support _.chain()/_().
In TypeScript, they support chaining through a very complex series of wrappers around every output type. Perhaps Flow could make this better via a flexible syntax that allows us to actually instruct the typechecker as to how it should interpret calls to this object.
It would be great if we could define a $Proxy:
$Proxy<Target, ArgTypeTransform, ReturnTypeTransform>
As in:
type LodashChainWrapper<T, U> = $Proxy<
Lodash,
(...args: any) => (T, ...args),
(out: U) => LodashChainWrapper<U>
>;
declare module 'lodash' {
declare class Lodash {
chain<T>(value: T): LodashChainWrapper<T>;
// ...
filter<T>(array: ?Array<T>, predicate?: Predicate<T>): Array<T>;
}
}
The idea is that Flow could understand that any function called on the result of chain() already has its first parameter filled in, and that it returns the proxy itself. The syntax above probably needs a lot of fleshing out.
Yes, we are _very_ interested in providing type combinators like this. Lodash is an excellent API to target. We're also looking at Immutable.js and Redux :)
@bhosmer and I have been thinking about this. Look out for updates in the coming months.
Most helpful comment
Yes, we are _very_ interested in providing type combinators like this. Lodash is an excellent API to target. We're also looking at Immutable.js and Redux :)
@bhosmer and I have been thinking about this. Look out for updates in the coming months.