Skip to content

Omitting duplicate definition of properties on object deconstruction #30574

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

Closed
5 tasks
AlseinX opened this issue Mar 25, 2019 · 2 comments
Closed
5 tasks

Omitting duplicate definition of properties on object deconstruction #30574

AlseinX opened this issue Mar 25, 2019 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@AlseinX
Copy link

AlseinX commented Mar 25, 2019

Search Terms

deconstruct parameter

Suggestion

Add any syntax convenience for deconstructing a value object (or just for function parameters) without specifying each property.

Use Cases

For example, currently, when we need to define a function with something like a settings object (without an existing interface or type alias defined, for it should be where it belongs to), we must either access the properties like foobar.foo, foobar.bar with repeatedly a lot of foobar., or deconstruct it like

({ foo, bar, baz }: { foo: string, bar: number, baz: boolean }) => {
    //...
}

But property names are duplicately specified, which is very painful and ungraceful especially when there are a lot of properties with long names.

Examples

({ ... }: { foo: string, bar: number, baz: boolean }) => {
    //...
}

which should extract all properties from the argument (which may depend on the type definition instead of the enumeration of keys, for not breaking the guidelines)

({ foo as string, bar as number, baz as boolean }) => {
    //...
}

actually using ":" instead of "as" would be but it already means alias naming.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 25, 2019
@RyanCavanaugh
Copy link
Member

See #29526

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants