Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created December 28, 2017 00:07
Show Gist options
  • Save zerobias/6e49651079d23f173f95ecc49b6a6ee1 to your computer and use it in GitHub Desktop.
Save zerobias/6e49651079d23f173f95ecc49b6a6ee1 to your computer and use it in GitHub Desktop.
Infinite nested property lookup in flow
//@flow
declare function deepSeq<P>(
...path: P
): $TupleMap<P, <T, Prop>(prop: Prop) => T => $ElementType<T, Prop>>
declare var pipe: $ComposeReverse
const target: 'target' = 'target'
const example = {
foo: {
bar: {
value: {
nested: target,
}
}
}
}
const step1 = pipe(...deepSeq(
'foo',
'bar',
'value'
))(example)
const step2 = pipe(...deepSeq(
'nested'
))(step1)
;(step1: { nested: 'target' })
/*
* $ExpectError
* string literal `target`.
* This type is incompatible with number
*/
;(step2: number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment