Reputation: 15
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
Reputation: 323
you cannot put optional parameters before mandatory parameters
(label:string, shop?:string, brand?:string)
should work
Upvotes: 2