From 04f28a1d7668f0a5ff04c83558a1b8acbd5f39ac Mon Sep 17 00:00:00 2001 From: SZ-CHENG HUANG Date: Sun, 5 Jul 2020 19:05:07 +0800 Subject: [PATCH] Flow: Fix the example for width subtyping (#558) --- flow.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/flow.md b/flow.md index 4b58a316e..61d4df7df 100644 --- a/flow.md +++ b/flow.md @@ -144,7 +144,7 @@ See: [Optional properties](https://flow.org/en/docs/types/primitives/#toc-option ## Objects {: .-three-column} -### Extra object fields +### Width subtyping ```js type Artist = { @@ -156,14 +156,13 @@ type Artist = { ```js const a: Artist = { name: 'Miguel Migs', - label: 'Naked Music' + label: 'Naked Music', + genre: 'House' // ✓ OK } - -a.genre = 'House' // ✓ OK ``` {: 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/) @@ -178,10 +177,13 @@ type Artist = {| {: data-line="1,4"} ```js -const a: Artist = { ··· } -a.genre = 'House' // ✗ Error +const a: Artist = { + 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.