utils.tsx 838 B

123456789101112131415161718192021
  1. import {Organization, SharedViewOrganization} from 'app/types';
  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. }