0

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")
1
  • Install an IDE. A required parameter cannot follow an optional parameter. is what the error says. Commented Mar 23, 2020 at 9:55

1 Answer 1

2

you cannot put optional parameters before mandatory parameters

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.