Flow: Remove unsealed objects

Created on 1 Feb 2019  路  6Comments  路  Source: facebook/flow

unsealed objects seem to be unintuitive to most users new to Flow. It also seems to be a common source of unsoundness in mature projects.

enhancement feature request unsealed objects

Most helpful comment

Probably as lint rule?

All 6 comments

Probably as lint rule?

@TrySound I believe that's in relation to exact objects, not unsealed objects but maybe there's some implications with defaulting to exact objects on unsealed objects I'm not understanding.

@goodmind A flow lint rule would be great! But there's still the problem of having to do {...null} if you want to create an empty, but not unsealed object.

js const a: { foo: string} = {}; // No error?!

Wow finally I understand all the weird bugs!

If you were allowed to assign any property to inexact object, then reading it back would be any but you wouldn鈥檛 have to make an empty object be weird in its definition.. wouldn鈥檛 that still allow unsealed usage untyped but not lead to many problems for people trying to use flow?

{} could be an exact object in some contexts and unsealed in others:

// exact
const foo1: {| bar?: boolean |} = {};
foo1.bar = true;

// unsealed
const foo2 = {};
foo2.baz = 1;

this is very important as unsealed objects are common only in facebook code base and no one else is familiar with this concept specially those who want to have sound type system

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NgoKnows picture NgoKnows  路  40Comments

cletusw picture cletusw  路  52Comments

gcanti picture gcanti  路  48Comments

STRML picture STRML  路  48Comments

danvk picture danvk  路  73Comments