Created
December 28, 2017 00:07
-
-
Save zerobias/6e49651079d23f173f95ecc49b6a6ee1 to your computer and use it in GitHub Desktop.
Infinite nested property lookup in flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@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