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

entityHelpers.getFieldValue returns wrong type #1140

Open
BraunreutherA opened this issue May 10, 2022 · 1 comment
Open

entityHelpers.getFieldValue returns wrong type #1140

BraunreutherA opened this issue May 10, 2022 · 1 comment
Labels
stale Used to mark when there was no activity for a set period of time

Comments

@BraunreutherA
Copy link

Hi there,

it seems the https://github.com/contentful/field-editors/blob/master/packages/_shared/src/utils/entityHelpers.ts getFieldValue return the wrong type string | undefined. When the Field is not a string field it would return another type.

As we would like to use the method in our App, would it be possible to

  1. change the returned type to unknown | undefined

or

  1. use a generic type like
export function getFieldValue<T = string>({
  /**
   * Expects an entity fetched with a flag Skip-Transformation: true
   */
  entity,
  fieldId,
  localeCode,
  defaultLocaleCode,
}: {
  entity: {
    fields: { [key: string]: { [valueKey: string]: string | undefined } };
  };
  fieldId: string;
  localeCode: string;
  defaultLocaleCode: string;
}): T | undefined {
  const values = get(entity, ['fields', fieldId]);
  if (!isObject(values)) {
    return;
  }

  const firstLocaleCode = Object.keys(values)[0];

  return values[localeCode] || values[defaultLocaleCode] || values[firstLocaleCode];
}

Thanks

Alex

@github-actions
Copy link

github-actions bot commented Aug 5, 2022

Marking issue as stale since there was no acitivty for 30 days

@github-actions github-actions bot added the stale Used to mark when there was no activity for a set period of time label Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Used to mark when there was no activity for a set period of time
Projects
None yet
Development

No branches or pull requests

1 participant