typescript - Access instance passed when destructuring -


i discovering destructuring feature in typescript , seems timesaver. wonder how can refer instance passed function when destructuring used. example below:

function fn({foo, bar}) {     // access instance passed function? } class {     constructor(public foo: number, public bar: number) {}; } fn(new a(1,9)); 

do have arguments list or missing something?

you can use destructuring inside method , not parameter , enjoy both worlds

function fn(a: a){  var {foo, bar} = a; }  class a{     foo:number;     bar:number; }  fn(new a()); 

look here transpiles to, can have idea of how works , not magic. here documentation typescript destructuring


Comments