typescript - What is the meaning of an object param in a function signature? -


what meaning of object param in function signature? came across code snippet, , i'm not sure what's going on here.

export const items = (state: = [], {type, payload}) => {   case (type) {     ...   } }; 

i don't understand {type, payload} in function signature.

this example of destructuring.

you can see this:

let items = (state: = [], {type, payload}) => {  }; 

compiles on typescript playground:

var items = function (state, _a) {      if (state === void 0) { state = []; }      var type = _a.type, payload = _a.payload; }; 

and can infer means second parameter of function object property called "type", , property called "payload". further, able refer "type" , "payload" directly in function body:

let items = (state: = [], {type, payload}) => {     console.log(type);     console.log(payload); };  let myobj = {     payload: "blue",     type: "no-type" }  items(null, myobj); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -