Kipper
Kipper copied to clipboard
[Feature] Implement spread operator for objects and arrays allowing the direct insertion of another object or array
Is there an existing proposal for this?
- [X] I have searched the existing issues
This feature does not exist in the latest version
- [X] I am using the latest version
Proposal
Add support for the spread syntax, which allows the direct insertion of arrays or objects into other arrays or objects.
Examples:
- Arrays:
var arr1: Array<num> = [1, 2, 3]; var arr2: Array<num> = [4, 5, 6]; var newArray: Array<num> = [...arr1, ...arr2, 7, 8, 9]; // -> [1, 2, 3, 4, 5, 6, 7, 8, 9]
- Objects:
var obj1 = { x: 1, y: 2, }; var obj2 = { z: 3, } var newObj = { ...obj1, ...obj2, };
Exact behaviour / changes you want
- [ ] Add syntax for the spread operator into the parser and allow it as a valid member of array and object literals.
- [ ] Add built-in functions
spreadArr
andspreadObj
, which implement the underlying functionality. - [ ] Add appropriate type checks and implement code generation for JavaScript and TypeScript.