TypeScript - pass to constructor entire object -
i have class @ type script: export class child { name:string; age:number; } i want force class instances have properties class declaration has. for example, if firebase object: myfirebaseservice.getchild(id).then(function(child){ var currentchild = new child(child); }) so when object is: {name:"ben", color:"db"}, want result be: currentchild = {"name":"ben"} becouse "color" not field of "child". i tried this: export class child { name:string; age:number; constructor(tempchild:child = null) { if (tempchild){ (var prop in tempchild) { this[prop] = tempchild[prop]; } } } } but not help. "currentchild" of fields , attached them class instance. (of course, can use following code: export class child { name:string; age:number; constructor(tempchild:child = null) { if (tempchild){ this.nam = tempchild.name; this.age =tempchild.age