如何在Typescript中的可选参数中创建函数

如何在Typescript中的可选参数中创建函数,typescript,function,Typescript,Function,我想知道如何拥有一个带有参数选项的函数 我有一个我拥有的功能 标签、品牌和车间参数。 但它不起作用,我不知道如何修复 const getTransaction = (shop?:string, brand?:string, label:string) => { if(shop && brand === null){ return label }else { return shop + brand; } } getTransaction("brand","top

我想知道如何拥有一个带有参数选项的函数

我有一个我拥有的功能 标签、品牌和车间参数。 但它不起作用,我不知道如何修复

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")

不能将可选参数置于必需参数之前


(标签:string,shop?:string,brand?:string)
应该有效

您不能将可选参数放在强制性参数之前


(标签:string,shop?:string,brand?:string)
应该可以工作

安装IDE<代码>必需参数不能跟在可选参数后面。是错误提示。请安装IDE<代码>必需参数不能跟在可选参数后面。是错误提示。