contentful.js icon indicating copy to clipboard operation
contentful.js copied to clipboard

Type for Sys missing archived Entry fields

Open RavenHursT opened this issue 2 years ago • 2 comments

Expected Behavior

Referencing fields for archived entries shouldn't result in a TypeScript compilation error

Actual Behavior

Archived entry fields are missing from type declaration, so TS errors abound when dealing w/ these fields

Possible Solution

Add archived entry fields to Sys type definition

Steps to Reproduce

const entry: Entry<any> = req.body
const isArchived = entry.sys.archivedVersion

Context

I'm trying to consume entry events from a webhook that I've created and when trying to handle events for archived entries, I'm seeing TS errors due to none of the archived fields being present on the TS type definition here: https://github.com/contentful/contentful.js/blob/master/index.d.ts#L152-L168

Environment

  • Language Version: v14.18.1
  • Package Manager Version: 6.14.15
  • Operating System: Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64
  • Package Version: [email protected]
  • Which API are you using?: Webhook request for entries

RavenHursT avatar Apr 01 '22 06:04 RavenHursT

I've been able to overcome this limitation for the time being with the following work-around:

interface AugmentedContenfulSys extends Sys {
  archivedVersion: number
}

interface AugmentedContenfulEntry extends Entry<any> {
  sys: AugmentedContenfulSys
}

RavenHursT avatar Apr 01 '22 07:04 RavenHursT

Hello,

could you maybe have a look if the same error happens with the new TypeScript version of contentful.js? You can install it via npm i contentful@beta-v10

You can find more info and specific docs here: https://github.com/contentful/contentful.js/tree/beta-v10

andreascful avatar May 30 '22 12:05 andreascful

Hey @RavenHursT 👋 , We expected this to be solved with the latest major release (which was a complete re-write). Please feel free to re-open again if the error still occurs.

marcolink avatar Jun 07 '23 07:06 marcolink