type.d.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * 全局类型定义
  3. */
  4. /** 接口返回值 */
  5. declare interface apiResDataType {
  6. code: number
  7. data: any
  8. message: string
  9. }
  10. /*
  11. store
  12. */
  13. /** 菜单 */
  14. declare interface menuType {
  15. path: string
  16. title: string
  17. icon: string
  18. component: string
  19. children: menuType[]
  20. meta: {
  21. routeType: "layout" | "singlepage" //菜单或者单页 模式
  22. }
  23. }
  24. /**
  25. *type tool
  26. */
  27. /**
  28. * 提取obj中的某个属性的值类型
  29. *
  30. *例: type a={b:{c:1}}
  31. *
  32. * type c=ExtractVByK<a,"b"> /{c:number}
  33. */
  34. declare type ExtractVByK<T extends Record<string, any>, P extends keyof T> = T[P]
  35. /**
  36. * 获取 数组的类型
  37. *
  38. * 例: type a=string[]
  39. *
  40. * type b=ArrElement< a > //string 另外: type b=a[number] 可以获取数组的类型,同时也能获取元祖的类型
  41. */
  42. declare type ArrElement<ArrType extends any[]> = ArrType extends (infer ElementType)[] ? ElementType : never
  43. /**
  44. * 将obj的某些类型变为可选
  45. *
  46. * 例: type a={a:string,b:string,c:string}
  47. *
  48. * type b=ObjPartial< a , 'a'|'b' > //{a?:string,b?:string,c:string}
  49. */
  50. declare type ObjPartial<T extends Record<string, any>, P extends keyof T> = Partial<Pick<T, P>> & Omit<T, P>