index.d.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * @license Angular v19.2.13
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. /**
  7. * @description
  8. *
  9. * Represents a type that a Component or other object is instances of.
  10. *
  11. * An example of a `Type` is `MyCustomComponent` class, which in JavaScript is represented by
  12. * the `MyCustomComponent` constructor function.
  13. *
  14. * @publicApi
  15. */
  16. declare const Type: FunctionConstructor;
  17. interface Type<T> extends Function {
  18. new (...args: any[]): T;
  19. }
  20. /**
  21. * Information about how a type or `InjectionToken` interfaces with the DI
  22. * system. This describes:
  23. *
  24. * 1. *How* the type is provided
  25. * The declaration must specify only one of the following:
  26. * - A `value` which is a predefined instance of the type.
  27. * - A `factory` which defines how to create the given type `T`, possibly
  28. * requesting injection of other types if necessary.
  29. * - Neither, in which case the type is expected to already be present in the
  30. * injector hierarchy. This is used for internal use cases.
  31. *
  32. * 2. *Where* the type is stored (if it is stored)
  33. * - The `providedIn` parameter specifies which injector the type belongs to.
  34. * - The `token` is used as the key to store the type in the injector.
  35. */
  36. interface ɵɵInjectableDeclaration<T> {
  37. /**
  38. * Specifies that the given type belongs to a particular `Injector`,
  39. * `NgModule`, or a special scope (e.g. `'root'`).
  40. *
  41. * `any` is deprecated and will be removed soon.
  42. *
  43. * A value of `null` indicates that the injectable does not belong to any
  44. * scope, and won't be stored in any injector. For declarations with a
  45. * factory, this will create a new instance of the type each time it is
  46. * requested.
  47. */
  48. providedIn: Type<any> | 'root' | 'platform' | 'any' | null;
  49. /**
  50. * The token to which this definition belongs.
  51. *
  52. * Note that this may not be the same as the type that the `factory` will create.
  53. */
  54. token: unknown;
  55. /**
  56. * Factory method to execute to create an instance of the injectable.
  57. */
  58. factory?: (t?: Type<any>) => T;
  59. /**
  60. * In a case of no explicit injector, a location where the instance of the injectable is stored.
  61. */
  62. value?: T;
  63. }
  64. /**
  65. * A `Type` which has a `ɵprov: ɵɵInjectableDeclaration` static field.
  66. *
  67. * `InjectableType`s contain their own Dependency Injection metadata and are usable in an
  68. * `InjectorDef`-based `StaticInjector`.
  69. *
  70. * @publicApi
  71. */
  72. interface InjectionToken<T> extends Type<T> {
  73. ɵprov: ɵɵInjectableDeclaration<T>;
  74. }
  75. /**
  76. * Value returned if the key-value pair couldn't be found in the context
  77. * hierarchy.
  78. */
  79. declare const NOT_FOUND: unique symbol;
  80. /**
  81. * Error thrown when the key-value pair couldn't be found in the context
  82. * hierarchy. Context can be attached below.
  83. */
  84. declare class NotFoundError extends Error {
  85. constructor(message: string);
  86. }
  87. /**
  88. * Type guard for checking if an unknown value is a NotFound.
  89. */
  90. declare function isNotFound(e: unknown): e is NotFound;
  91. /**
  92. * Type union of NotFound and NotFoundError.
  93. */
  94. type NotFound = typeof NOT_FOUND | NotFoundError;
  95. interface Injector {
  96. retrieve<T>(token: InjectionToken<T>, options?: unknown): T | NotFound;
  97. }
  98. declare function getCurrentInjector(): Injector | undefined | null;
  99. declare function setCurrentInjector(injector: Injector | null | undefined): Injector | undefined | null;
  100. export { NOT_FOUND, NotFoundError, getCurrentInjector, isNotFound, setCurrentInjector };
  101. export type { InjectionToken, Injector, NotFound, ɵɵInjectableDeclaration };