Flow: Very basic type-checking seems broken.

Created on 18 Sep 2019  路  4Comments  路  Source: facebook/flow

Flow version: v0.107

Not sure if I'm crazy, but some very basic type checking seems to be just broken? Given

type Record = {
   foo: number,
   bar: string
}

const x: Record = {};

Expected behavior

Error indicating x is not of type Record

Actual behavior

No errors!

bug needs triage

Most helpful comment

{} is special in flow, it's an unsealed object. The easiest way to avoid this is to do something like { ...null } which will result in a regular empty object.

All 4 comments

If you make the object exact, it does correctly errors.
The same if you add a property to the empty object.
I think this is related to: https://github.com/facebook/flow/issues/2977
And the weird differences you get with empty objects.

{} is special in flow, it's an unsealed object. The easiest way to avoid this is to do something like { ...null } which will result in a regular empty object.

Wow, that really clashes with your expectations after hearing Flow is supposed to value "soundness".

Always appreciate the hard work of devs to provide the community things for free, but feels like this whole project would be better off managing your expectations on it a differently.

Going to close this since #7424 seems to track this.

:+1: on removing unsealed objects fwiw.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gcanti picture gcanti  路  48Comments

danvk picture danvk  路  73Comments

sebmck picture sebmck  路  113Comments

Gozala picture Gozala  路  54Comments

opensrcery picture opensrcery  路  88Comments