Skip to content

Simplify object destructuring in argument #14856

Closed
@antanas-arvasevicius

Description

@antanas-arvasevicius

Hello,
when doing some prototyping and playing with object destructuring in function argument I've noticed that I must duplicate identifier names in type information and if there are many variables it looks heavier:

function mainLayoutComponent({banners, profile, cart}: { banners: Component, profile: Component, cart: Component }): any { }

Proposal:
My suggestion would be that destructuring in function argument position would allow type information definition if object type is not explicitly defined:
function mainLayoutComponent({banners: Component, profile: Component, cart: Component}): any { }

It would be handy. I don't know how that sounds from language design perspective as it feels like it will be possible to define a function which argument identifier is "unknown" but with given type information.

Compiler could translate that kind of construct into destructuring syntax before compilation.

Note: I've seen propsal with :: operator (#13471) which was rejected, but this "special treatment" of destructuring in argument space looks ES6, ES7 compatible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions