Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

merge-exclusive.d.ts 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Helper type. Not useful on its own.
  2. type Without<FirstType, SecondType> = {[KeyType in Exclude<keyof FirstType, keyof SecondType>]?: never};
  3. /**
  4. Create a type that has mutually exclusive keys.
  5. This type was inspired by [this comment](https://github.com/Microsoft/TypeScript/issues/14094#issuecomment-373782604).
  6. This type works with a helper type, called `Without`. `Without<FirstType, SecondType>` produces a type that has only keys from `FirstType` which are not present on `SecondType` and sets the value type for these keys to `never`. This helper type is then used in `MergeExclusive` to remove keys from either `FirstType` or `SecondType`.
  7. @example
  8. ```
  9. import {MergeExclusive} from 'type-fest';
  10. interface ExclusiveVariation1 {
  11. exclusive1: boolean;
  12. }
  13. interface ExclusiveVariation2 {
  14. exclusive2: string;
  15. }
  16. type ExclusiveOptions = MergeExclusive<ExclusiveVariation1, ExclusiveVariation2>;
  17. let exclusiveOptions: ExclusiveOptions;
  18. exclusiveOptions = {exclusive1: true};
  19. //=> Works
  20. exclusiveOptions = {exclusive2: 'hi'};
  21. //=> Works
  22. exclusiveOptions = {exclusive1: true, exclusive2: 'hi'};
  23. //=> Error
  24. ```
  25. */
  26. export type MergeExclusive<FirstType, SecondType> =
  27. (FirstType | SecondType) extends object ?
  28. (Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType) :
  29. FirstType | SecondType;