Skip to content

Commit

Permalink
use appropriate type for empty obj in ts
Browse files Browse the repository at this point in the history
  • Loading branch information
eastandwestwind committed Sep 19, 2023
1 parent 4881704 commit aebde26
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 3 additions & 1 deletion clients/fides-js/src/fides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
ConsentMethod,
SaveConsentPreference,
ConsentMechanism,
EmptyExperience,
} from "./lib/consent-types";
import {
constructFidesRegionString,
Expand Down Expand Up @@ -231,7 +232,8 @@ const init = async ({
}

let shouldInitOverlay: boolean = options.isOverlayEnabled;
let effectiveExperience: PrivacyExperience | undefined | {} = experience;
let effectiveExperience: PrivacyExperience | undefined | EmptyExperience =
experience;
let fidesRegionString: string | null = null;

if (shouldInitOverlay) {
Expand Down
2 changes: 1 addition & 1 deletion clients/fides-js/src/lib/consent-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type EmptyExperience = {};
export type EmptyExperience = Record<PropertyKey, never>;

export interface FidesConfig {
// Set the consent defaults from a "legacy" Privacy Center config.json.
Expand Down
9 changes: 3 additions & 6 deletions clients/fides-js/src/lib/consent-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ export const isEmptyExperience = (obj: unknown): obj is EmptyExperience =>
* Returns true if privacy experience has notices
*/
export const experienceHasNotices = (
experience: PrivacyExperience | undefined | {}
experience: PrivacyExperience | undefined | EmptyExperience
): boolean =>
Boolean(
experience &&
!isEmptyExperience(experience) &&
// fixme: how to tell ts that privacy_notices exists on experience?
experience.privacy_notices &&
experience.privacy_notices.length > 0
);
Expand Down Expand Up @@ -161,25 +160,23 @@ export const validateOptions = (options: FidesOptions): boolean => {
* Determines whether experience is valid and relevant notices exist within the experience
*/
export const experienceIsValid = (
effectiveExperience: PrivacyExperience | undefined | {},
effectiveExperience: PrivacyExperience | undefined | EmptyExperience,
options: FidesOptions
): boolean => {
if (!experienceHasNotices(effectiveExperience)) {
if (!effectiveExperience || !experienceHasNotices(effectiveExperience)) {
debugLog(
options.debug,
`Privacy experience has no notices. Skipping overlay initialization.`
);
return false;
}
// @ts-ignore
if (effectiveExperience.component !== ComponentType.OVERLAY) {
debugLog(
options.debug,
"No experience found with overlay component. Skipping overlay initialization."
);
return false;
}
// @ts-ignore
if (!effectiveExperience.experience_config) {
debugLog(
options.debug,
Expand Down
3 changes: 2 additions & 1 deletion clients/fides-js/src/services/fides/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ComponentType,
EmptyExperience,
LastServedNoticeSchema,
NoticesServedRequest,
PrivacyExperience,
Expand All @@ -22,7 +23,7 @@ export const fetchExperience = async (
fidesApiUrl: string,
debug: boolean,
fidesUserDeviceId?: string | null
): Promise<PrivacyExperience | {}> => {
): Promise<PrivacyExperience | EmptyExperience> => {
debugLog(
debug,
`Fetching experience for userId: ${fidesUserDeviceId} in location: ${userLocationString}`
Expand Down

0 comments on commit aebde26

Please sign in to comment.