@@ -11,6 +11,7 @@ import {
1111 FlagValueType ,
1212 Hook ,
1313 HookContext ,
14+ JsonValue ,
1415 Logger ,
1516 Provider ,
1617 ResolutionDetails ,
@@ -154,38 +155,41 @@ export class OpenFeatureClient implements Client {
154155 * Performs a flag evaluation that returns a string.
155156 *
156157 * @param {string } flagKey The flag key uniquely identifies a particular flag
157- * @param {string } defaultValue The value returned if an error occurs
158+ * @template {string} T A optional generic argument constraining the string
159+ * @param {T } defaultValue The value returned if an error occurs
158160 * @param {EvaluationContext } context The evaluation context used on an individual flag evaluation
159161 * @param {FlagEvaluationOptions } options Additional flag evaluation options
160- * @returns {Promise<string > } Flag evaluation response
162+ * @returns {Promise<T > } Flag evaluation response
161163 */
162- async getStringValue (
164+ async getStringValue < T extends string = string > (
163165 flagKey : string ,
164- defaultValue : string ,
166+ defaultValue : T ,
165167 context ?: EvaluationContext ,
166168 options ?: FlagEvaluationOptions
167- ) : Promise < string > {
168- return ( await this . getStringDetails ( flagKey , defaultValue , context , options ) ) . value ;
169+ ) : Promise < T > {
170+ return ( await this . getStringDetails < T > ( flagKey , defaultValue , context , options ) ) . value ;
169171 }
170172
171173 /**
172174 * Performs a flag evaluation that a returns an evaluation details object.
173175 *
174176 * @param {string } flagKey The flag key uniquely identifies a particular flag
175- * @param {boolean } defaultValue The value returned if an error occurs
177+ * @template {string} T A optional generic argument constraining the string
178+ * @param {T } defaultValue The value returned if an error occurs
176179 * @param {EvaluationContext } context The evaluation context used on an individual flag evaluation
177180 * @param {FlagEvaluationOptions } options Additional flag evaluation options
178- * @returns {Promise<EvaluationDetails<string >> } Flag evaluation details response
181+ * @returns {Promise<EvaluationDetails<T >> } Flag evaluation details response
179182 */
180- getStringDetails (
183+ getStringDetails < T extends string = string > (
181184 flagKey : string ,
182- defaultValue : string ,
185+ defaultValue : T ,
183186 context ?: EvaluationContext ,
184187 options ?: FlagEvaluationOptions
185- ) : Promise < EvaluationDetails < string > > {
186- return this . evaluate < string > (
188+ ) : Promise < EvaluationDetails < T > > {
189+ return this . evaluate < T > (
187190 flagKey ,
188- this . _provider . resolveStringEvaluation ,
191+ // this isolates providers from our restricted string generic argument.
192+ this . _provider . resolveStringEvaluation as ( ) => Promise < EvaluationDetails < T > > ,
189193 defaultValue ,
190194 'string' ,
191195 context ,
@@ -197,38 +201,41 @@ export class OpenFeatureClient implements Client {
197201 * Performs a flag evaluation that returns a number.
198202 *
199203 * @param {string } flagKey The flag key uniquely identifies a particular flag
200- * @param {number } defaultValue The value returned if an error occurs
204+ * @template {number} T A optional generic argument constraining the number
205+ * @param {T } defaultValue The value returned if an error occurs
201206 * @param {EvaluationContext } context The evaluation context used on an individual flag evaluation
202207 * @param {FlagEvaluationOptions } options Additional flag evaluation options
203- * @returns {Promise<number > } Flag evaluation response
208+ * @returns {Promise<T > } Flag evaluation response
204209 */
205- async getNumberValue (
210+ async getNumberValue < T extends number = number > (
206211 flagKey : string ,
207- defaultValue : number ,
212+ defaultValue : T ,
208213 context ?: EvaluationContext ,
209214 options ?: FlagEvaluationOptions
210- ) : Promise < number > {
215+ ) : Promise < T > {
211216 return ( await this . getNumberDetails ( flagKey , defaultValue , context , options ) ) . value ;
212217 }
213218
214219 /**
215220 * Performs a flag evaluation that a returns an evaluation details object.
216221 *
217222 * @param {string } flagKey The flag key uniquely identifies a particular flag
218- * @param {number } defaultValue The value returned if an error occurs
223+ * @template {number} T A optional generic argument constraining the number
224+ * @param {T } defaultValue The value returned if an error occurs
219225 * @param {EvaluationContext } context The evaluation context used on an individual flag evaluation
220226 * @param {FlagEvaluationOptions } options Additional flag evaluation options
221- * @returns {Promise<EvaluationDetails<number >> } Flag evaluation details response
227+ * @returns {Promise<EvaluationDetails<T >> } Flag evaluation details response
222228 */
223- getNumberDetails (
229+ getNumberDetails < T extends number = number > (
224230 flagKey : string ,
225- defaultValue : number ,
231+ defaultValue : T ,
226232 context ?: EvaluationContext ,
227233 options ?: FlagEvaluationOptions
228- ) : Promise < EvaluationDetails < number > > {
229- return this . evaluate < number > (
234+ ) : Promise < EvaluationDetails < T > > {
235+ return this . evaluate < T > (
230236 flagKey ,
231- this . _provider . resolveNumberEvaluation ,
237+ // this isolates providers from our restricted number generic argument.
238+ this . _provider . resolveNumberEvaluation as ( ) => Promise < EvaluationDetails < T > > ,
232239 defaultValue ,
233240 'number' ,
234241 context ,
@@ -240,12 +247,13 @@ export class OpenFeatureClient implements Client {
240247 * Performs a flag evaluation that returns an object.
241248 *
242249 * @param {string } flagKey The flag key uniquely identifies a particular flag
243- * @param {object } defaultValue The value returned if an error occurs
250+ * @template {JsonValue} T A optional generic argument describing the structure
251+ * @param {T } defaultValue The value returned if an error occurs
244252 * @param {EvaluationContext } context The evaluation context used on an individual flag evaluation
245253 * @param {FlagEvaluationOptions } options Additional flag evaluation options
246- * @returns {Promise<object > } Flag evaluation response
254+ * @returns {Promise<T > } Flag evaluation response
247255 */
248- async getObjectValue < T extends object > (
256+ async getObjectValue < T extends JsonValue = JsonValue > (
249257 flagKey : string ,
250258 defaultValue : T ,
251259 context ?: EvaluationContext ,
@@ -258,12 +266,13 @@ export class OpenFeatureClient implements Client {
258266 * Performs a flag evaluation that a returns an evaluation details object.
259267 *
260268 * @param {string } flagKey The flag key uniquely identifies a particular flag
261- * @param {object } defaultValue The value returned if an error occurs
269+ * @template {JsonValue} T A optional generic argument describing the structure
270+ * @param {T } defaultValue The value returned if an error occurs
262271 * @param {EvaluationContext } context The evaluation context used on an individual flag evaluation
263272 * @param {FlagEvaluationOptions } options Additional flag evaluation options
264- * @returns {Promise<EvaluationDetails<object >> } Flag evaluation details response
273+ * @returns {Promise<EvaluationDetails<T >> } Flag evaluation details response
265274 */
266- getObjectDetails < T extends object > (
275+ getObjectDetails < T extends JsonValue = JsonValue > (
267276 flagKey : string ,
268277 defaultValue : T ,
269278 context ?: EvaluationContext ,
0 commit comments