Closed kevinbarabash closed 5 years ago
I knew about https://github.com/piotrwitek/utility-types. It's great to see the same thing in the opposite direction. Is there any reason not to use flown
to help flowgen
add some more ✅the Supported column?
Ah, this is flowgen
repo, not flow
😬
I don't think I can add library to generated files, nor I think your Pick
is correct, because it makes indexer object
That's too bad. It's because $ElementType<T, K>
is doing $ElementType<T, "x" | "y">
. That's unfortunate. TypeScript's combination of mapped types and conditional types is really powerful.
I don't think I can add library to generated files
Is it possible to insert an import
(or require
) at the top the generated file?
It wouldn't work with flow-typed
, because it doesn't support dependencies between packages.
Also flown
Pick
doesn't match with typescript one, which uses union, while flown
uses tuple for keys, I can convert union to tuple, but then it wouldn't work with Pick<X, SomeTypeAlias>
Flow utility types are pretty weak, they break too much, TypeScript's mapped + conditional types are more reliable really.
This has to do with lazy evaluation vs eager evaluation, TypeScript uses latter, Flow can't because they have $Call
which should handle polymorphism lazily
If you're interested in more powerful things just check my PRs about utility types 😀
Wow! Tuple reduce and tuple spread seem pretty powerful in their own right, but should be even more powerful when used together.
In https://www.typescriptlang.org/docs/handbook/advanced-types.html,
Pick
is defined as:Translating this to flow yields:
Example