IssueRaiser

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

Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments

github (Other)

Combining destructuring with parameter properties

buzinasOct 19, 2015, 3:32 PM

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.

Comment on this issue