IssueRaiser

Add spread/rest higher-order types operator

The spread type is a new type operator that types the [TC39 stage 3 object spread operator](https://github.com/sebmarkbage/ecmascript-rest-spread). Its counterpart, the difference type, will type the proposed object rest destructuring operator. The spread type `{ ...A, ...B }` combines the properties, but not the call or construct signatures, of entities A and B. The pull request is at #11150. The original issue for spread/rest types is #2103. Note that this proposal deviates from the specification by keeping all properties except methods, not just own enumerable ones. ## Proposal syntax The type syntax in this proposal differs from the type syntax as implemented in order to treat spread as a binary operator. Three rules are needed to convert the `{ ...spread1, ...spread2 }` syntax to binary syntax `spread1 ... spread2`. 1. `{ ...spread }` becomes `{} ... spread`. 2. `{ a, b, c, ...d}` becomes `{a, b, c} ... d` 3. Multiple spreads inside an object literal are treated as sequences of binary spreads: `{ a, b, c, ...d, ...e, f, g}` becomes `{a, b, c} ... d ... e ... { f, g }`. ## Type Relationships - Identity: `A ... A ... A` is equivalent to `A ... A` and `A ... A` is equivalent to `{} ... A`. - Commutativity: `A ... B` is _not_ equivalent to `B ... A`. Properties of `B` overwrite properties of `A` with the same name in `A ... B`. - Associativity: `(A ... B) ... C` is equivalent to `A ... (B ... C)`. `...` is right-associative. - Distributivity: Spread is distributive over `|

Posted by sandersn on Sep 6, 2016, 6:00 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments

github (E-commerce)

Add spread/rest higher-order types operator

sandersnSep 6, 2016, 6:00 PM

The spread type is a new type operator that types the [TC39 stage 3 object spread operator](https://github.com/sebmarkbage/ecmascript-rest-spread). Its counterpart, the difference type, will type the proposed object rest destructuring operator. The spread type `{ ...A, ...B }` combines the properties, but not the call or construct signatures, of entities A and B. The pull request is at #11150. The original issue for spread/rest types is #2103. Note that this proposal deviates from the specification by keeping all properties except methods, not just own enumerable ones. ## Proposal syntax The type syntax in this proposal differs from the type syntax as implemented in order to treat spread as a binary operator. Three rules are needed to convert the `{ ...spread1, ...spread2 }` syntax to binary syntax `spread1 ... spread2`. 1. `{ ...spread }` becomes `{} ... spread`. 2. `{ a, b, c, ...d}` becomes `{a, b, c} ... d` 3. Multiple spreads inside an object literal are treated as sequences of binary spreads: `{ a, b, c, ...d, ...e, f, g}` becomes `{a, b, c} ... d ... e ... { f, g }`. ## Type Relationships - Identity: `A ... A ... A` is equivalent to `A ... A` and `A ... A` is equivalent to `{} ... A`. - Commutativity: `A ... B` is _not_ equivalent to `B ... A`. Properties of `B` overwrite properties of `A` with the same name in `A ... B`. - Associativity: `(A ... B) ... C` is equivalent to `A ... (B ... C)`. `...` is right-associative. - Distributivity: Spread is distributive over `|

Comments (0)

No comments yet. Start the discussion.

Comment on this issue