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.

conditional-keys.d.ts 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. Extract the keys from a type where the value type of the key extends the given `Condition`.
  3. Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
  4. @example
  5. ```
  6. import {ConditionalKeys} from 'type-fest';
  7. interface Example {
  8. a: string;
  9. b: string | number;
  10. c?: string;
  11. d: {};
  12. }
  13. type StringKeysOnly = ConditionalKeys<Example, string>;
  14. //=> 'a'
  15. ```
  16. To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
  17. @example
  18. ```
  19. type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
  20. //=> 'a' | 'c'
  21. ```
  22. */
  23. export type ConditionalKeys<Base, Condition> = NonNullable<
  24. // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
  25. {
  26. // Map through all the keys of the given base type.
  27. [Key in keyof Base]:
  28. // Pick only keys with types extending the given `Condition` type.
  29. Base[Key] extends Condition
  30. // Retain this key since the condition passes.
  31. ? Key
  32. // Discard this key since the condition fails.
  33. : never;
  34. // Convert the produced object into a union type of the keys which passed the conditional test.
  35. }[keyof Base]
  36. >;