In TypeScript 3.6.3 it seems I cannot use destructured assignment to initialize Class properties in a constructor, even if the passed object conforms to an appropriate Interface. Is there a way to achieve this, or is there good rationale for why it's not allowed?
interface TestInt {
name: string,
name2: string
}
class TestClass {
name: string
name2: string
constructor(t: TestInt){
{this.name, this.name2} = t
}
}
// static errors:
// Property 'name' has no initializer and is not definitely assigned in the constructor.
// Property 'name' is used before being assigned.
let a = new TestClass({name: 'mom', name2:'dad'})
console.log(a.name)
console.log(a.name2)
// undefined
// undefined