Flow: Using $Shape does not correctly infer undefined fields?

Created on 12 Jun 2020  路  2Comments  路  Source: facebook/flow

Flow version: 0.126.1 (but older versions are also affected)

Expected behavior

The expected behavior is that Flow would throw an error on the last line:

type User = $Shape<{|
  +name: string,
  +email: string,
|}>;

const user: User = {
  ...null,
};

user.name.toLowerCase();
//        ^^^^^^^^^^^
//        Would expect error here, since
//        `name` can still be undefined

Actual behavior

It's incorrectly accepted as a valid program, reporting no errors. See Try-Flow.

It may be worth nothing that if you avoid the use of $Shape in the User definition, this bug _is_ getting caught correctly. See Try-Flow.

bug needs triage

Most helpful comment

See #7316, #7730, #7566, #5702, #6039, #6796.

That's how $Shape works, it's an unsound escape hatch. Use

type Partial<T> = $Rest<T, {...}>

instead. Try Flow.

All 2 comments

See #7316, #7730, #7566, #5702, #6039, #6796.

That's how $Shape works, it's an unsound escape hatch. Use

type Partial<T> = $Rest<T, {...}>

instead. Try Flow.

please close your question so we can center in the unsewered ones

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cubika picture cubika  路  3Comments

Beingbook picture Beingbook  路  3Comments

pelotom picture pelotom  路  3Comments

bennoleslie picture bennoleslie  路  3Comments

ghost picture ghost  路  3Comments