shared-types.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // tslint:disable:no-shadowed-variable
  2. /**
  3. * A recursive implementation of the Partial<T> type.
  4. * Source: https://stackoverflow.com/a/49936686/772859
  5. */
  6. export type DeepPartial<T> = {
  7. [P in keyof T]?: T[P] extends Array<infer U>
  8. ? Array<DeepPartial<U>>
  9. : T[P] extends ReadonlyArray<infer U>
  10. ? ReadonlyArray<DeepPartial<U>>
  11. : DeepPartial<T[P]>
  12. };
  13. // tslint:enable:no-shadowed-variable
  14. // tslint:disable:ban-types
  15. /**
  16. * A type representing the type rather than instance of a class.
  17. */
  18. export type Type<T> = {
  19. new (...args: any[]): T;
  20. } & Function;
  21. /**
  22. * A type describing the shape of a paginated list response
  23. */
  24. export type PaginatedList<T> = {
  25. items: T[];
  26. totalItems: number;
  27. };
  28. /**
  29. * An entity ID
  30. */
  31. export type ID = string | number;
  32. export type CustomFieldType = 'string' | 'localeString' | 'int' | 'float' | 'boolean' | 'datetime';
  33. export interface CustomFieldConfig {
  34. name: string;
  35. type: CustomFieldType;
  36. }
  37. export interface CustomFields {
  38. Address?: CustomFieldConfig[];
  39. Customer?: CustomFieldConfig[];
  40. Product?: CustomFieldConfig[];
  41. ProductOption?: CustomFieldConfig[];
  42. ProductOptionGroup?: CustomFieldConfig[];
  43. ProductVariant?: CustomFieldConfig[];
  44. User?: CustomFieldConfig[];
  45. }
  46. /**
  47. * This interface should be implemented by any entity which can be extended
  48. * with custom fields.
  49. */
  50. export interface HasCustomFields {
  51. customFields: CustomFieldsObject;
  52. }
  53. export type MayHaveCustomFields = Partial<HasCustomFields>;
  54. export type CustomFieldsObject = { [key: string]: any; };