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

getFieldValue not compatible with Item.fields property #1020

Open
coreyasmith opened this issue May 16, 2022 · 1 comment
Open

getFieldValue not compatible with Item.fields property #1020

coreyasmith opened this issue May 16, 2022 · 1 comment
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work keep

Comments

@coreyasmith
Copy link
Contributor

Description

The getFieldValue<T> helper method

export function getFieldValue<T>(
is not compatible with the Item.fields property so field values can't be extracted from "ContentList" field types using the getFieldValue<T> method without casting.

getFieldValue<T> expects type ComponentRendering or { [name: string]: Field | Item[] }, but Item.fields is of type { [name: string]: Field | Item | Item[] | undefined; }, so Item.fields cannot be passed to getFieldValue.

Expected behavior

In the Styleguide-FieldUsage-ContentList component (https://github.com/Sitecore/jss/blob/dev/packages/create-sitecore-jss/src/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-ContentList.tsx), I should be able to use getFieldValue on lines 37 or 48 as follows, without casting:

<p>
  Field: {getFieldValue<string>(listItem.fields, "textField")}
</p>

Steps To Reproduce

Try to pass the fields of an item in a multilist or treelist field to the getFieldValue<T> helper method as described above.

Possible Fix

Change the Fields type in jss/utils.ts

type Fields = { [name: string]: Field | Item[] };
to:

type Fields = { [name: string]: Field | Item | Item[] | undefined; }; 

Your Environment

  • Sitecore Version: 9.3
  • JSS Version: 12
  • Browser Name and version: N/A
  • Operating System and version (desktop or mobile): N/A
  • Link to your project (if available): N/A

Screenshots

No screenshots necessary.

@illiakovalenko
Copy link
Contributor

I added an issue to the backlog, we will triage that

@illiakovalenko illiakovalenko added the backlog Issue/PR/discussion is reviewed and added to backlog for the further work label Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work keep
Projects
None yet
Development

No branches or pull requests

2 participants