Created
June 30, 2016 14:16
-
-
Save mgadda/8d6d08dc3979febcd82d31014165dd1b to your computer and use it in GitHub Desktop.
Why does line 16 of index.js produce a Flow error?
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
[ignore] | |
[include] | |
[libs] | |
[options] |
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 */ | |
type EncodableType = string | number | boolean; | |
type EncodableData = { [key: string]: EncodableType | EncodableType[] }; | |
function encode(data: EncodableData): string { | |
return "the encoded data"; | |
} | |
encode({ data: 10 }); // OK | |
encode({ data: [1,2,3] }); // OK | |
const data = [1,2,3]; | |
encode({ data }); // OK | |
const data2: number[] = [1,2,3]; | |
encode({ data2 }); // ERROR | |
/* | |
$ flow check | |
index.js:16 | |
16: encode({ data2 }); | |
^^^^^^^^^^^^^^^^^ function call | |
16: encode({ data2 }); | |
^^^^^ array type. This type is incompatible with | |
3: type EncodableData = { [key: string]: EncodableType | EncodableType[] }; | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ union: EncodableType | array type | |
Member 1: | |
3: type EncodableData = { [key: string]: EncodableType | EncodableType[] }; | |
^^^^^^^^^^^^^ EncodableType | |
Error: | |
16: encode({ data2 }); | |
^^^^^ array type. This type is incompatible with | |
3: type EncodableData = { [key: string]: EncodableType | EncodableType[] }; | |
^^^^^^^^^^^^^ union: string | number | boolean | |
Member 1: | |
2: type EncodableType = string | number | boolean; | |
^^^^^^ string | |
Error: | |
16: encode({ data2 }); | |
^^^^^ array type. This type is incompatible with | |
2: type EncodableType = string | number | boolean; | |
^^^^^^ string | |
Member 2: | |
2: type EncodableType = string | number | boolean; | |
^^^^^^ number | |
Error: | |
16: encode({ data2 }); | |
^^^^^ array type. This type is incompatible with | |
2: type EncodableType = string | number | boolean; | |
^^^^^^ number | |
Member 3: | |
2: type EncodableType = string | number | boolean; | |
^^^^^^^ boolean | |
Error: | |
16: encode({ data2 }); | |
^^^^^ array type. This type is incompatible with | |
2: type EncodableType = string | number | boolean; | |
^^^^^^^ boolean | |
Member 2: | |
3: type EncodableData = { [key: string]: EncodableType | EncodableType[] }; | |
^^^^^^^^^^^^^^^ array type | |
Error: | |
2: type EncodableType = string | number | boolean; | |
^^^^^^ string. This type is incompatible with | |
15: const data2: number[] = [1,2,3]; | |
^^^^^^ number | |
Found 1 error | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment