Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSSDK-9897] update return type of getFeatureVariable method #887

Merged
merged 3 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/core/project_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
VariableType,
VariationVariable,
Integration,
FeatureVariableValue,
} from '../../shared_types';

interface TryCreatingProjectConfigConfig {
Expand Down Expand Up @@ -692,8 +693,8 @@ export const getTypeCastValue = function(
variableValue: string,
variableType: VariableType,
logger: LogHandler
): unknown {
let castValue;
): FeatureVariableValue {
let castValue : FeatureVariableValue;

switch (variableType) {
case FEATURE_VARIABLE_TYPES.BOOLEAN:
Expand Down
1 change: 1 addition & 0 deletions lib/export_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {
UserAttributeValue,
UserAttributes,
OptimizelyConfig,
FeatureVariableValue,
OptimizelyVariable,
OptimizelyVariation,
OptimizelyExperiment,
Expand Down
7 changes: 4 additions & 3 deletions lib/optimizely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
FeatureVariable,
OptimizelyOptions,
OptimizelyDecideOption,
FeatureVariableValue,
OptimizelyDecision,
Client,
} from '../shared_types';
Expand Down Expand Up @@ -777,7 +778,7 @@ export default class Optimizely implements Client {
* type, or null if the feature key is invalid or
* the variable key is invalid
*/
getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): unknown {
getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): FeatureVariableValue {
try {
if (!this.isValidInstance()) {
this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariable');
Expand Down Expand Up @@ -819,7 +820,7 @@ export default class Optimizely implements Client {
variableType: string | null,
userId: string,
attributes?: UserAttributes
): unknown {
): FeatureVariableValue {
if (!this.validateInputs({ feature_key: featureKey, variable_key: variableKey, user_id: userId }, attributes)) {
return null;
}
Expand Down Expand Up @@ -911,7 +912,7 @@ export default class Optimizely implements Client {
variation: Variation | null,
variable: FeatureVariable,
userId: string
): unknown {
): FeatureVariableValue {
const configObj = this.projectConfigManager.getConfig();
if (!configObj) {
return null;
Expand Down
4 changes: 3 additions & 1 deletion lib/shared_types.ts
mikechu-optimizely marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ export interface OptimizelyExperiment {
};
}

export type FeatureVariableValue = number | string | boolean | object | null;

export interface OptimizelyVariable {
id: string;
key: string;
Expand All @@ -330,7 +332,7 @@ export interface Client {
getForcedVariation(experimentKey: string, userId: string): string | null;
isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean;
getEnabledFeatures(userId: string, attributes?: UserAttributes): string[];
getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): unknown;
getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): FeatureVariableValue;
getFeatureVariableBoolean(
featureKey: string,
variableKey: string,
Expand Down
Loading