Its confusing that object maps require ... (they are not exact)
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Related: https://github.com/facebook/flow/issues/6640
## Proposal
Classify object maps as being "exact" because they fully define what can be in the object, as opposed to inexact. I had assumed maps were exact, maybe because the syntax makes the definition of inexact look like "and anything else" which isn't true for maps..
When you use a map, essentially the object becomes exact..
```
/* @flow */
type A = { [string]: number, ... };
// errors
const b: A = { 'a': 'a' };
type B = { 'b'?: number, ... };
// no error
const c: B = { 'a': 'a' };
```
e.g. it acts as if `{| [string]: number |}` because new properties that are not having the value of type number cannot be defined.
My main problem is that when we all follow your guidelines for your switching to exact object types, when we reach the last step and get rid of the `{||}` syntax we will be left with having to define maps using the very verbose syntax `{ [string]: string, ... }` which I think looks a bit strange (it looks like string to string or anything else).
An alternative could be to introduce a new syntax for maps like `{ ...[string]: string }` to indicate that the `...` is not additional properties but actually the map property that is defined.
Contributor guide
Assessment
This issue has not been assessed yet.