Sitecore / jss

Software development kit for JavaScript developers building web applications with Sitecore Experience Platform
https://jss.sitecore.com
Apache License 2.0
262 stars 272 forks source link

Add support for ContentList / MultiList to the RouteData['fields'] return type #1021

Closed thaiphan closed 2 years ago

thaiphan commented 2 years ago

Description

RouteData['fields'] only returns the Field type. However, this type definition is insufficient if your route has a ContentList field...

const fields: RouteData['fields'] = {
  pageTitle: {value: 'Reasons to use our service'}, // Field - this is currently supported
  canonicalUrl: {value: {href: '/reasons-to-use-our-service'}}, // Field
  // Item[] - this will result in a type error
  robots: [
    {
      name: 'nofollow',
      displayName: 'nofollow',
      fields: {
        name: {
          value: 'nofollow'
        },
        value: {
          value: 'nofollow'
        },
      },
      // I noticed that these fields come back from Sitecore but aren't in the type def either
      id: '',
      url: '',
    }
  ]
}

Expected behavior

I think that RouterData['fields'] should return Field | Item[].

Possible Fix

export interface RouteData {
  fields?: {
    [name: string]: Field | Item[];
  }
}

Your Environment

illiakovalenko commented 2 years ago

Added issue to our backlog, we will triage that

illiakovalenko commented 2 years ago

Implemented in #1061