facebook / facebook/flow

Disallow intersection of exact objects

Open
#8,158 3 comments 0 reactions 0 assignees View on GitHub
discussion
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

## Proposal

Intersections of exact objects does not make sense since they produce impossible type that can't be used. `{| a: number|} & {| b: string |}`produces an object type that only has property `a` and nothing else, but also has property `b` and nothing else. This indicates that intersections can only be used for inexact objects.

In optimal case the error message would be describing and maybe communicate why intersection of exact objects can't be used and suggest to use spreading instead.

This is important especially for newcomers and people who are used to write TS. I find my self very often explaining how and why intersection of exact objects can't be used.

I understand that this might not be big deal for FB, but for community it's important to make experience good for newcomers.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.