utils.tsx 864 B

12345678910111213141516171819202122232425
  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> = T extends object
  17. ? {
  18. [P in keyof T]?: DeepPartial<T[P]>;
  19. }
  20. : T;