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.

require-exactly-one.d.ts 1.2KB

1234567891011121314151617181920212223242526272829303132333435
  1. // TODO: Remove this when we target TypeScript >=3.5.
  2. type _Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
  3. /**
  4. Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
  5. Use-cases:
  6. - Creating interfaces for components that only need one of the keys to display properly.
  7. - Declaring generic keys in a single place for a single use-case that gets narrowed down via `RequireExactlyOne`.
  8. The caveat with `RequireExactlyOne` is that TypeScript doesn't always know at compile time every key that will exist at runtime. Therefore `RequireExactlyOne` can't do anything to prevent extra keys it doesn't know about.
  9. @example
  10. ```
  11. import {RequireExactlyOne} from 'type-fest';
  12. type Responder = {
  13. text: () => string;
  14. json: () => string;
  15. secure: boolean;
  16. };
  17. const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
  18. // Adding a `text` key here would cause a compile error.
  19. json: () => '{"message": "ok"}',
  20. secure: true
  21. };
  22. ```
  23. */
  24. export type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
  25. {[Key in KeysType]: (
  26. Required<Pick<ObjectType, Key>> &
  27. Partial<Record<Exclude<KeysType, Key>, never>>
  28. )}[KeysType] & _Omit<ObjectType, KeysType>;