line404
line404

Reputation: 15

How to create a function in optional parameter in Typescript

I wonderer how to have a function with parameter option.

I have a function who I have label, brand, and shop parameter. But it's not working and I don't know how to fix that..

const getTransaction = (shop?:string, brand?:string, label:string) => {
if(shop && brand === null){
   return label
}else {
  return shop + brand;
  }
}
getTransaction("brand","topshop", "topshop - brand")
getTransaction(null,null, "topshop - brand")

Upvotes: 0

Views: 67

Answers (1)

Ch3micaL
Ch3micaL

Reputation: 323

you cannot put optional parameters before mandatory parameters

(label:string, shop?:string, brand?:string) should work

Upvotes: 2

Related Questions