types.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /** Alias type for value that can be null */
  2. export type Nullable<T> = T | null;
  3. /**
  4. * Alias type for number that are floats
  5. * @ignorenaming
  6. */
  7. export type float = number;
  8. /**
  9. * Alias type for number that are doubles.
  10. * @ignorenaming
  11. */
  12. export type double = number;
  13. /**
  14. * Alias type for number that are integer
  15. * @ignorenaming
  16. */
  17. export type int = number;
  18. /** Alias type for number array or Float32Array */
  19. export type FloatArray = number[] | Float32Array;
  20. /** Alias type for number array or Float32Array or Int32Array or Uint32Array or Uint16Array */
  21. export type IndicesArray = number[] | Int32Array | Uint32Array | Uint16Array;
  22. /**
  23. * Alias for types that can be used by a Buffer or VertexBuffer.
  24. */
  25. export type DataArray = number[] | ArrayBuffer | ArrayBufferView;
  26. /**
  27. * Alias type for primitive types
  28. * @ignorenaming
  29. */
  30. type Primitive = undefined | null | boolean | string | number | Function;
  31. /**
  32. * Type modifier to make all the properties of an object Readonly
  33. */
  34. export type Immutable<T> = T extends Primitive
  35. ? T
  36. : T extends Array<infer U>
  37. ? ReadonlyArray<U>
  38. : /* T extends Map<infer K, infer V> ? ReadonlyMap<K, V> : // es2015+ only */
  39. DeepImmutable<T>;
  40. /**
  41. * Type modifier to make all the properties of an object Readonly recursively
  42. */
  43. export type DeepImmutable<T> = T extends Primitive
  44. ? T
  45. : T extends Array<infer U>
  46. ? DeepImmutableArray<U>
  47. : /* T extends Map<infer K, infer V> ? DeepImmutableMap<K, V> : // es2015+ only */
  48. DeepImmutableObject<T>;
  49. /**
  50. * Type modifier to make object properties readonly.
  51. */
  52. export type DeepImmutableObject<T> = { readonly [K in keyof T]: DeepImmutable<T[K]> };
  53. /** @hidden */
  54. interface DeepImmutableArray<T> extends ReadonlyArray<DeepImmutable<T>> { }
  55. /** @hidden */
  56. /* interface DeepImmutableMap<K, V> extends ReadonlyMap<DeepImmutable<K>, DeepImmutable<V>> {} // es2015+ only */