Flow version: 0.38
Received error:
Flow: object literal. This type is incompatible with object type
Expected error
Flow: undefined. This type is incompatible with number
How to reproduce:
type PhotoDetailsType = {
path: string,
width: number,
height: number,
size: number, // here should be ?number
}
type Photo = {
mq: PhotoDetailsType,
}
const photo: Photo = {
mq: {
path: '/static/images/profilePhotos/6596/696840_mq.jpg',
width: 920,
height: 1636,
size: undefined, // this causes a problem
}
}
It gave the correct error in 0.37.4 (Try Flow - toggle the version in the top right):
18: size: undefined, // this causes a problem
^ undefined. This type is incompatible with
6: size: number, // here should be ?number
^ number
One more example (minimalistic):
Received error (v0.38.0):
Flow: object literal. This type is incompatible with object type
Expected error (v0.37.4):
Flow: undefined. This type is incompatible with the expected return type of string
I can confirm this bug, it is annoying because it sends you down the wrong rabbit hole
Seeing the same issue in flow 0.45.0
And seeing the same in 0.47.0
Still an issue with 0.50.0 ;)
Also seems misleading when you try parameter destructuring.
function blah({ thing = null }: { thing: Thing | null })
Tells me null
is incompatible with object type
and also that object type
is incompatible with null
. Maybe this is another bug.
I'm not sure what the "still an issue" comments are referring to, but the original example is resolved.
Note that the issue was just that Try Flow didn't display the entire error message. It now matches the Flow CLI, which outputs:
Error: test.js:14
v
14: const photo: Photo = {
15: mq: {
16: path: '/static/images/profilePhotos/6596/696840_mq.jpg',
...:
21: }
^ object literal. This type is incompatible with
14: const photo: Photo = {
^^^^^ object type
Property `mq` is incompatible:
v
15: mq: {
16: path: '/static/images/profilePhotos/6596/696840_mq.jpg',
17: width: 920,
...:
20: }
^ object literal. This type is incompatible with
11: mq: PhotoDetailsType,
^^^^^^^^^^^^^^^^ object type
Property `size` is incompatible:
19: size: undefined, // this causes a problem
^^^^^^^^^ undefined. This type is incompatible with
7: size: number, // here should be ?number
^^^^^^ number
Found 1 error
@samwgoldman I was getting this error from the CLI not from Try Flow.
@madorb OK, sorry about that. In any event, both output the same information now, which is enough information to be useful, I think.
Most helpful comment
Still an issue with 0.50.0 ;)