@@ -28,11 +28,8 @@ export function Injectable<Token extends TokenType, Service>(
28
28
* The dependencies are specified as tokens, and the factory function
29
29
* will receive these dependencies as arguments in the order they are listed.
30
30
*
31
- * **Note:** Dependencies must be specified as constant literals to allow TypeScript to ensure type safety.
32
- *
33
- * **Note:** Starting with TypeScript version 5, the `as const` assertion in the example below is not needed
34
- * due to the introduction of [const type parameters feature](
35
- * https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#const-type-parameters).
31
+ * **Important:** This function requires **TypeScript 5 or later** due to the use of `const` type parameters.
32
+ * Users on TypeScript 4 and earlier must use {@link InjectableCompat} instead.
36
33
*
37
34
* @example
38
35
* ```ts
@@ -100,6 +97,28 @@ export function Injectable(
100
97
return factory ;
101
98
}
102
99
100
+ /**
101
+ * A compatibility version of {@link Injectable} for TypeScript 4 and earlier users.
102
+ * This function behaves identically to {@link Injectable} but requires the use of `as const` on the dependencies array.
103
+ *
104
+ * @deprecated Use {@link Injectable} instead. This function is provided for compatibility with TypeScript 4
105
+ * and earlier versions and will be removed in future releases.
106
+ *
107
+ * @see {@link Injectable } for detailed usage instructions and examples.
108
+ */
109
+ export function InjectableCompat <
110
+ Token extends TokenType ,
111
+ Tokens extends readonly TokenType [ ] ,
112
+ Params extends readonly any [ ] ,
113
+ Service ,
114
+ > (
115
+ token : Token ,
116
+ dependencies : Tokens ,
117
+ fn : ( ...args : Tokens [ "length" ] extends Params [ "length" ] ? Params : void [ ] ) => Service
118
+ ) : ReturnType < typeof Injectable > {
119
+ return Injectable ( token , dependencies , fn ) ;
120
+ }
121
+
103
122
/**
104
123
* Creates an Injectable factory function for an InjectableClass.
105
124
*
0 commit comments