Skip to content

Commit f94a323

Browse files
committed
Change userProfileServiceInstance to type unknown
1 parent 5beccf7 commit f94a323

File tree

2 files changed

+11
-9
lines changed
  • packages/optimizely-sdk/lib/utils

2 files changed

+11
-9
lines changed

packages/optimizely-sdk/lib/utils/event_tags_validator/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const MODULE_NAME = 'EVENT_TAGS_VALIDATOR';
2525

2626
/**
2727
* Validates user's provided event tags
28-
* @param {object} eventTags
28+
* @param {unknown} eventTags
2929
* @return {boolean} true if event tags are valid
3030
* @throws If event tags are not valid
3131
*/

packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ const MODULE_NAME = 'USER_PROFILE_SERVICE_VALIDATOR';
2626

2727
/**
2828
* Validates user's provided user profile service instance
29-
* @param {object} userProfileServiceInstance
29+
* @param {unknown} userProfileServiceInstance
3030
* @return {boolean} true if the instance is valid
3131
* @throws If the instance is not valid
3232
*/
3333

34-
//TODO: Use defined UserProfileService interface instead of 'Record<string, unknown>'
35-
export function validate(userProfileServiceInstance: Record<string, unknown>): boolean {
36-
if (typeof userProfileServiceInstance.lookup !== 'function') {
37-
throw new Error(sprintf(ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, MODULE_NAME, "Missing function 'lookup'"));
38-
} else if (typeof userProfileServiceInstance.save !== 'function') {
39-
throw new Error(sprintf(ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, MODULE_NAME, "Missing function 'save'"));
34+
export function validate(userProfileServiceInstance: unknown): boolean {
35+
if (typeof userProfileServiceInstance === 'object' && userProfileServiceInstance !== null) {
36+
if (typeof userProfileServiceInstance['lookup'] !== 'function') {
37+
throw new Error(sprintf(ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, MODULE_NAME, "Missing function 'lookup'"));
38+
} else if (typeof userProfileServiceInstance['save'] !== 'function') {
39+
throw new Error(sprintf(ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, MODULE_NAME, "Missing function 'save'"));
40+
}
41+
return true;
4042
}
41-
return true;
43+
throw new Error(sprintf(ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, MODULE_NAME));
4244
}

0 commit comments

Comments
 (0)