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.

entries.d.ts 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {ArrayEntry, MapEntry, ObjectEntry, SetEntry} from './entry';
  2. type ArrayEntries<BaseType extends readonly unknown[]> = Array<ArrayEntry<BaseType>>;
  3. type MapEntries<BaseType> = Array<MapEntry<BaseType>>;
  4. type ObjectEntries<BaseType> = Array<ObjectEntry<BaseType>>;
  5. type SetEntries<BaseType extends Set<unknown>> = Array<SetEntry<BaseType>>;
  6. /**
  7. Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entries` type will return the type of that collection's entries.
  8. For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
  9. @see `Entry` if you want to just access the type of a single entry.
  10. @example
  11. ```
  12. import {Entries} from 'type-fest';
  13. interface Example {
  14. someKey: number;
  15. }
  16. const manipulatesEntries = (examples: Entries<Example>) => examples.map(example => [
  17. // Does some arbitrary processing on the key (with type information available)
  18. example[0].toUpperCase(),
  19. // Does some arbitrary processing on the value (with type information available)
  20. example[1].toFixed()
  21. ]);
  22. const example: Example = {someKey: 1};
  23. const entries = Object.entries(example) as Entries<Example>;
  24. const output = manipulatesEntries(entries);
  25. // Objects
  26. const objectExample = {a: 1};
  27. const objectEntries: Entries<typeof objectExample> = [['a', 1]];
  28. // Arrays
  29. const arrayExample = ['a', 1];
  30. const arrayEntries: Entries<typeof arrayExample> = [[0, 'a'], [1, 1]];
  31. // Maps
  32. const mapExample = new Map([['a', 1]]);
  33. const mapEntries: Entries<typeof map> = [['a', 1]];
  34. // Sets
  35. const setExample = new Set(['a', 1]);
  36. const setEntries: Entries<typeof setExample> = [['a', 'a'], [1, 1]];
  37. ```
  38. */
  39. export type Entries<BaseType> =
  40. BaseType extends Map<unknown, unknown> ? MapEntries<BaseType>
  41. : BaseType extends Set<unknown> ? SetEntries<BaseType>
  42. : BaseType extends unknown[] ? ArrayEntries<BaseType>
  43. : BaseType extends object ? ObjectEntries<BaseType>
  44. : never;