-
-
Save jonakyd/ac000b3fe30161d2b185083756b57176 to your computer and use it in GitHub Desktop.
Flow quirk
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
function a(args: { a1: Array<number>, a2: number }) { | |
// Should Error | |
console.log(args.a1.join(',')); | |
} | |
a({}); | |
// Ok, we try the exact object now | |
function b(args: {| a1: Array<number>, a2: number |}) { | |
console.log(args.a1.join(',')); | |
} | |
// $ExpectError | |
// Good | |
// b({}); | |
b({a1: [1,2,3], a2: 1}); | |
// What if we want optional properties? | |
function c(args: {| a1?: Array<number>, a2?: number |}) { | |
if (args.a1) { | |
console.log(args.a1.join(',')); | |
} | |
} | |
// Why it's error? | |
//c({}); | |
// Still error WTF | |
//c({a1: undefined, a2:undefined}); | |
const sealedObject = { | |
a1: undefined, | |
a2: undefined, | |
}; | |
// Flow is ok now. But this way doesnt feel right... | |
c(sealedObject); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Required props and optional hack with
&