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.

readonly-deep.d.ts 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {Primitive} from './basic';
  2. /**
  3. Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
  4. This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.
  5. Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
  6. @example
  7. ```
  8. // data.json
  9. {
  10. "foo": ["bar"]
  11. }
  12. // main.ts
  13. import {ReadonlyDeep} from 'type-fest';
  14. import dataJson = require('./data.json');
  15. const data: ReadonlyDeep<typeof dataJson> = dataJson;
  16. export default data;
  17. // test.ts
  18. import data from './main';
  19. data.foo.push('bar');
  20. //=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
  21. ```
  22. */
  23. export type ReadonlyDeep<T> = T extends Primitive | ((...arguments: any[]) => unknown)
  24. ? T
  25. : T extends ReadonlyMap<infer KeyType, infer ValueType>
  26. ? ReadonlyMapDeep<KeyType, ValueType>
  27. : T extends ReadonlySet<infer ItemType>
  28. ? ReadonlySetDeep<ItemType>
  29. : T extends object
  30. ? ReadonlyObjectDeep<T>
  31. : unknown;
  32. /**
  33. Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
  34. */
  35. interface ReadonlyMapDeep<KeyType, ValueType>
  36. extends ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>> {}
  37. /**
  38. Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
  39. */
  40. interface ReadonlySetDeep<ItemType>
  41. extends ReadonlySet<ReadonlyDeep<ItemType>> {}
  42. /**
  43. Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
  44. */
  45. type ReadonlyObjectDeep<ObjectType extends object> = {
  46. readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
  47. };