You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-1Lines changed: 19 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Some of these differences are subjective (e.g. error readability), and I'd love
27
27
| specifying generic parameters for type definitions | yes | yes |
28
28
| typings for public libraries | plenty of well maintained typings | a handful of mostly incomplete typings |
29
29
| unique features | <ul><li>autocomplete for object construction</li><li>declarable `this` in functions (typing `someFunction.bind()`)</li><li>large library of typings</li><li>more flexible [type mapping via iteration](https://github.com/Microsoft/TypeScript/pull/12114)</li><li>namespacing</li></ul> | <ul><li>variance</li><li>existential types `*` (deprecated since 0.72)</li><li>testing potential code-paths when types not declared for maximum inference</li><li>`$Diff<A, B>` type</li></ul> |
30
-
| type spread operator |[shipped](https://github.com/Microsoft/TypeScript/pull/28234) > 3.2rc|[shipped](https://github.com/facebook/flow/commit/ad443dc92879ae21705d4c61b942ba2f8ad61e4d) >=0.42 |
30
+
| type spread operator |no ([planned](https://github.com/microsoft/TypeScript/issues/10727))|[shipped](https://github.com/facebook/flow/commit/ad443dc92879ae21705d4c61b942ba2f8ad61e4d) >=0.42 |
31
31
| support for nullish coalescing proposal |[shipped](https://github.com/microsoft/TypeScript/pull/32883) > 3.7beta | yes |
32
32
| support for decorators proposal | yes, legacy proposal | only parsing of legacy proposal, no type-checking |
33
33
| support for extending built-in types | yes | no |
@@ -1069,6 +1069,24 @@ function incAge(age: Age): number {
1069
1069
}
1070
1070
```
1071
1071
1072
+
## Object type spread
1073
+
1074
+
Object type spread acts as [object spread](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) but for types. Unlike [intersection types](https://flow.org/en/docs/types/intersections/) type spreads work with exact object types and overwrite existing properties.
1075
+
1076
+
```js
1077
+
type Foo = {| foo: string, bar: string |}
1078
+
type Bar = {| bar: number |}
1079
+
1080
+
type FooBarIntersection = Foo & Bar
1081
+
type FooBarSpread = {|...Foo, ...Bar |}
1082
+
1083
+
const fooBarInterect:FooBarIntersection= { foo:'123', bar:12 } // not ok
1084
+
const fooBarString:FooBarSpread= { foo:'123', bar:'string' } // not ok
1085
+
const fooBar:FooBarSpread= { foo:'123', bar:12 } // ok
1086
+
```
1087
+
1088
+
While TypeScript does understand object spread, the support for object type spread is [not implemented](https://github.com/microsoft/TypeScript/issues/10727).
0 commit comments