Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Implement spread operator for objects and arrays allowing the direct insertion of another object or array #668

Open
2 of 5 tasks
Luna-Klatzer opened this issue Jul 18, 2024 · 0 comments
Labels
feature New feature or enhancement
Milestone

Comments

@Luna-Klatzer
Copy link
Member

Is there an existing proposal for this?

  • I have searched the existing issues

This feature does not exist in the latest version

  • 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 and spreadObj, which implement the underlying functionality.
  • Add appropriate type checks and implement code generation for JavaScript and TypeScript.
@Luna-Klatzer Luna-Klatzer added the feature New feature or enhancement label Jul 18, 2024
@Luna-Klatzer Luna-Klatzer added this to the v0.12.0 milestone Jul 18, 2024
@Luna-Klatzer Luna-Klatzer self-assigned this Jul 18, 2024
@Luna-Klatzer Luna-Klatzer removed their assignment Jul 18, 2024
@Luna-Klatzer Luna-Klatzer modified the milestones: v0.12.0, v0.13.0 Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Projects
Development

No branches or pull requests

1 participant