Skip to content

Commit 8b1ddb3

Browse files
committed
refactor: update types and methods to align with flag terminology
- Changed `UntypedFlag` payload type from a union to `any` for flexibility. - Refactored `Flag` type to use a default type of `{}` instead of `boolean | object | string | number | null`. - Updated `TypedFlags` and `TypedFeatures` types to reflect the new flag structure. - Renamed test cases and methods in `client.test.ts` to use `getFlag` and `getFlagDefinitions` for consistency with the flag-based approach. - Enhanced documentation to clarify the transition from features to flags in the SDK.
1 parent 5d2444e commit 8b1ddb3

4 files changed

Lines changed: 888 additions & 720 deletions

File tree

packages/node-sdk/src/types.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export type FeatureOverride =
213213
export type UntypedFlag =
214214
| {
215215
key: string;
216-
payload: boolean | object | string | number | null;
216+
payload: any;
217217
}
218218
| boolean;
219219

@@ -222,13 +222,12 @@ export type UntypedFlag =
222222
*
223223
* @typeParam TValue - The type of the flag value. Defaults to `boolean`.
224224
*/
225-
export type Flag<TValue extends boolean | object | string | number | null> =
226-
TValue extends boolean
227-
? boolean
228-
: {
229-
key: string;
230-
payload: TValue;
231-
};
225+
export type Flag<TValue extends {} = boolean> = TValue extends boolean
226+
? boolean
227+
: {
228+
key: string;
229+
payload: TValue;
230+
};
232231

233232
/**
234233
* @deprecated
@@ -380,14 +379,14 @@ export type TypedFeatures = keyof Flags extends never
380379
? Record<string, Feature>
381380
: {
382381
[TKey in keyof Flags]: Flags[TKey] extends FeatureWithRemoteConfigSignature
383-
? Flags[TKey] extends MultiVariateFlagSignature
382+
? Feature<Flags[TKey]["config"]>
383+
: Flags[TKey] extends MultiVariateFlagSignature
384384
? Feature<Flags[TKey]>
385-
: Feature<Flags[TKey]["config"]>
386-
: Feature;
385+
: Feature;
387386
};
388387

389388
/**
390-
* Describes a collection of evaluated flags.
389+
* Describes a collection of typed flags.
391390
*
392391
* @remarks
393392
* This types falls back to a generic `Record<string, Flag>` if the `Flags` interface
@@ -397,10 +396,16 @@ export type TypedFlags = keyof Flags extends never
397396
? Record<string, UntypedFlag>
398397
: {
399398
[TKey in keyof Flags]: Flags[TKey] extends FeatureWithRemoteConfigSignature
400-
? Flags[TKey] extends MultiVariateFlagSignature
401-
? Flag<Flags[TKey]["payload"]>
402-
: Flag<Flags[TKey]["config"]>
403-
: UntypedFlag;
399+
? {
400+
key: string;
401+
payload: Flags[TKey]["config"];
402+
}
403+
: Flags[TKey] extends MultiVariateFlagSignature
404+
? {
405+
key: string;
406+
payload: Flags[TKey]["payload"];
407+
}
408+
: UntypedFlag;
404409
};
405410

406411
/**

0 commit comments

Comments
 (0)