utils.tsx 956 B

123456789101112131415161718192021222324252627
  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. // eslint-disable-next-line prettier/prettier
  8. export function assert(_value: unknown): asserts _value {}
  9. // This declares a function which asserts that the expression called
  10. // value is of type Type:
  11. // eslint-disable-next-line prettier/prettier
  12. export function assertType<Type>(_value: unknown): asserts _value is Type {}
  13. export function isNotSharedOrganization(
  14. maybe: Organization | SharedViewOrganization
  15. ): maybe is Organization {
  16. return typeof (maybe as Organization).id !== 'undefined';
  17. }
  18. export type DeepPartial<T> = T extends object
  19. ? {
  20. [P in keyof T]?: DeepPartial<T[P]>;
  21. }
  22. : T;