utils.tsx 892 B

1234567891011121314151617181920212223242526
  1. import type {Organization, SharedViewOrganization} from './organization';
  2. // from:
  3. // - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
  4. // - https://www.typescriptlang.org/play/#example/assertion-functions
  5. // This declares a function which asserts that the expression called
  6. // value is true:
  7. export function assert(_value: unknown): asserts _value {}
  8. // This declares a function which asserts that the expression called
  9. // value is of type Type:
  10. export function assertType<Type>(_value: unknown): asserts _value is Type {}
  11. export function isNotSharedOrganization(
  12. maybe: Organization | SharedViewOrganization
  13. ): maybe is Organization {
  14. return typeof (maybe as Organization).id !== 'undefined';
  15. }
  16. export type DeepPartial<T> =
  17. T extends Record<PropertyKey, any>
  18. ? {
  19. [P in keyof T]?: DeepPartial<T[P]>;
  20. }
  21. : T;