Flow: Fix the example for width subtyping (#558)
This commit is contained in:
parent
a54b580e01
commit
04f28a1d76
18
flow.md
18
flow.md
|
@ -144,7 +144,7 @@ See: [Optional properties](https://flow.org/en/docs/types/primitives/#toc-option
|
||||||
## Objects
|
## Objects
|
||||||
{: .-three-column}
|
{: .-three-column}
|
||||||
|
|
||||||
### Extra object fields
|
### Width subtyping
|
||||||
|
|
||||||
```js
|
```js
|
||||||
type Artist = {
|
type Artist = {
|
||||||
|
@ -156,14 +156,13 @@ type Artist = {
|
||||||
```js
|
```js
|
||||||
const a: Artist = {
|
const a: Artist = {
|
||||||
name: 'Miguel Migs',
|
name: 'Miguel Migs',
|
||||||
label: 'Naked Music'
|
label: 'Naked Music',
|
||||||
|
genre: 'House' // ✓ OK
|
||||||
}
|
}
|
||||||
|
|
||||||
a.genre = 'House' // ✓ OK
|
|
||||||
```
|
```
|
||||||
{: data-line="6"}
|
{: data-line="6"}
|
||||||
|
|
||||||
You can add more fields to an object.
|
A type with more properties is "wider" and is a subtype of a "narrower" type.
|
||||||
|
|
||||||
See: [Width subtyping](https://flow.org/en/docs/lang/width-subtyping/)
|
See: [Width subtyping](https://flow.org/en/docs/lang/width-subtyping/)
|
||||||
|
|
||||||
|
@ -178,10 +177,13 @@ type Artist = {|
|
||||||
{: data-line="1,4"}
|
{: data-line="1,4"}
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const a: Artist = { ··· }
|
const a: Artist = {
|
||||||
a.genre = 'House' // ✗ Error
|
name: 'Miguel Migs',
|
||||||
|
label: 'Naked Music',
|
||||||
|
genre: 'House' // ✗ Error
|
||||||
|
}
|
||||||
```
|
```
|
||||||
{: data-line="2"}
|
{: data-line="4"}
|
||||||
|
|
||||||
Exact object types prevent extra properties from being added to an object.
|
Exact object types prevent extra properties from being added to an object.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue