ts 参数默认类型设置

 

 

常用的参数类型设置

    title: string;
    data: any[];
    type: string;
    QC: number;
    activeKey: string[];
    changeCollapse: any;

 例子:默认穿一个字符串数组的参数类型

export const getSettingKeys = async (UserSettingKeys:string[]) => {
  if(UserSettingKeys.length<1) return 

  const keys = UserSettingKeys;

  const res = await store.systemSettingManager.getConfigsByKeys({
    keys,
    objectId: store.currentUser.id,
    nestObject: true,
  });
  return res
};

 

有确定类型的默认值赋值

const fun = (num1: number = 1, num2?:number): number => {
    return num1 + (num2?num2:0)
}

 

posted @ 2022-02-24 11:47  明媚下雨天  阅读(2503)  评论(0编辑  收藏  举报