Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created October 13, 2017 21:17
Show Gist options
  • Save zerobias/d34b93b2e2f490f58f11084048b398bc to your computer and use it in GitHub Desktop.
Save zerobias/d34b93b2e2f490f58f11084048b398bc to your computer and use it in GitHub Desktop.
Flow flatten type
declare function flatten<
A,
B: $ReadOnlyArray<A> | A,
C: $ReadOnlyArray<B> | B,
D: $ReadOnlyArray<C> | C,
E: $ReadOnlyArray<D> | D,
>(xs: $ReadOnlyArray<E>): Array<A>
const listsList = [{
items: [[10, 2], 3, [0, 1, [2], [1, [2]], ],2, [2, 3]]
}]
const items = listsList.map(({ items }) => items)
const ok: number[] = flatten(items)
const t = flatten(items).map(x => x + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment