Combining destructuring with parameter properties
Today, we can take advantage of parameter properties to reduce the boilerplate, e.g: ``` typescript class Person { constructor(public firstName: string, public lastName: number, public age: number) { } } ``` Since 1.5, we can also use destructuring, e.g: ``` typescript class Person { firstName: string; lastName: string; age: number; constructor({ firstName, lastName, age } : { firstName: string, lastName: string, age: number }) { this.firstName = firstName; this.lastName = lastName; this.age = age; } } ``` I've tried in many ways to combine both features, but had no success. So: 1. Is it possible to combine them nowadays, and if yes, how? 2. If not, could it be an improvement to a future TypeScript version? E.g: ``` javascript class Person { constructor(public { firstName, lastName, age } : { firstName: string, lastName: string, age: number }) { } } // the code above would possibly transpile to: var Person = (function () { function Person(_a) { var firstName = _a.firstName, lastName = _a.lastName, age = _a.age; this.firstName = firstName; this.lastName = lastName; this.age = age; } return Person; })(); ```
Posted by buzinas on Oct 19, 2015, 3:32 PM
Tags
Related issues
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
Combining destructuring with parameter properties
Today, we can take advantage of parameter properties to reduce the boilerplate, e.g: ``` typescript class Person { constructor(public firstName: string, public lastName: number, public age: number) { } } ``` Since 1.5, we can also use destructuring, e.g: ``` typescript class Person { firstName: string; lastName: string; age: number; constructor({ firstName, lastName, age } : { firstName: string, lastName: string, age: number }) { this.firstName = firstName; this.lastName = lastName; this.age = age; } } ``` I've tried in many ways to combine both features, but had no success. So: 1. Is it possible to combine them nowadays, and if yes, how? 2. If not, could it be an improvement to a future TypeScript version? E.g: ``` javascript class Person { constructor(public { firstName, lastName, age } : { firstName: string, lastName: string, age: number }) { } } // the code above would possibly transpile to: var Person = (function () { function Person(_a) { var firstName = _a.firstName, lastName = _a.lastName, age = _a.age; this.firstName = firstName; this.lastName = lastName; this.age = age; } return Person; })(); ```
Comments (0)
No comments yet. Start the discussion.