diff --git a/website/en/docs/types/objects.md b/website/en/docs/types/objects.md index d27e183ff1b..fb3b23db6ae 100644 --- a/website/en/docs/types/objects.md +++ b/website/en/docs/types/objects.md @@ -229,6 +229,19 @@ properties to an exact object type. var foo: {| foo: string |} = { foo: "Hello", bar: "World!" }; // Error! ``` +If you need to combine many exact object types into one, instead of using an intersection type you should use the object type spread: + +```js +type FooT = {| foo: string |} +type BarT = {| bar: number |} + +type FooBarFailT = FooT & BarT +type FooBarT = {| ...FooT, ...BarT |} + +const fooBarFail: FooBarFailT = { foo: '123', bar: 12 } // Error! +const fooBar: FooBarT = { foo: '123', bar: 12 } +``` + ## Objects as maps Newer versions of the JavaScript standard include a `Map` class, but it is