From 9e0623db7173591f09bac1ed77e6a76802bae300 Mon Sep 17 00:00:00 2001 From: Tim Beyer Date: Thu, 24 Oct 2024 13:06:09 +0200 Subject: [PATCH] feat: give includes basic entry and asset types instead of any --- lib/types/entry.ts | 4 +- test/types/client/getEntries.test-d.ts | 191 ++++++++++++++++++------- 2 files changed, 141 insertions(+), 54 deletions(-) diff --git a/lib/types/entry.ts b/lib/types/entry.ts index 7be75e432..6a14a26a9 100644 --- a/lib/types/entry.ts +++ b/lib/types/entry.ts @@ -339,7 +339,7 @@ export type EntryCollection< > = ContentfulCollection> & { errors?: Array includes?: { - Entry?: any[] - Asset?: any[] + Entry?: Entry[] + Asset?: Asset[] } } diff --git a/test/types/client/getEntries.test-d.ts b/test/types/client/getEntries.test-d.ts index 54b900c9c..40fec8804 100644 --- a/test/types/client/getEntries.test-d.ts +++ b/test/types/client/getEntries.test-d.ts @@ -18,105 +18,192 @@ type Fields = { moreLinks: Entry[] } -type EntrySkeleton = EntrySkeletonType +// A skeleton with no fields +type BaseEntrySkeleton = EntrySkeletonType + +// Skeleton with some specific fields +type TestEntrySkeleton = EntrySkeletonType type Locale = 'en' -expectType>(await client.getEntry('entry-id')) -expectType>(await client.getEntry('entry-id')) -expectType>(await client.getEntries()) -expectType>(await client.getEntries()) +/** + * With no extra parameters + */ +expectType>(await client.getEntry('entry-id')) + +expectType>( + await client.getEntry('entry-id'), +) +expectType>(await client.getEntries()) + +expectType>( + await client.getEntries(), +) +expectType>((await client.getEntries()).includes!.Entry![0]) -expectType>( - await client.getEntries({ content_type: 'content-type-id' }), +expectType>( + await client.getEntries({ content_type: 'content-type-id' }), ) -expectError(await client.getEntries({ content_type: 'unexpected' })) -expectType>( - await client.getEntries({ +expectError(await client.getEntries({ content_type: 'unexpected' })) + +expectType>( + await client.getEntries({ content_type: 'content-type-id', }), ) -expectType>( +/** + * Without unresolvable Links + */ +expectType>( await client.withoutUnresolvableLinks.getEntry('entry-id'), ) -expectType>( - await client.withoutUnresolvableLinks.getEntry('entry-id'), +expectType>( + await client.withoutUnresolvableLinks.getEntry('entry-id'), ) -expectType>( + +expectType>( await client.withoutUnresolvableLinks.getEntries(), ) -expectType>( - await client.withoutUnresolvableLinks.getEntries(), + +expectType>( + await client.withoutUnresolvableLinks.getEntries(), ) -expectType>( +expectType>( + (await client.withoutUnresolvableLinks.getEntries()).includes!.Entry![0], +) + +/** + * Without link resolution + */ +expectType>( await client.withoutLinkResolution.getEntry('entry-id'), ) -expectType>( - await client.withoutLinkResolution.getEntry('entry-id'), + +expectType>( + await client.withoutLinkResolution.getEntry('entry-id'), ) -expectType>( + +expectType>( await client.withoutLinkResolution.getEntries(), ) -expectType>( - await client.withoutLinkResolution.getEntries(), + +expectType>( + await client.withoutLinkResolution.getEntries(), ) -expectType>( +expectType>( + (await client.withoutLinkResolution.getEntries()).includes!.Entry![0], +) + +/** + * With all Locales + */ +expectType>( await client.withAllLocales.getEntry('entry-id'), ) -expectType>( - await client.withAllLocales.getEntry('entry-id'), + +expectType>( + await client.withAllLocales.getEntry('entry-id'), ) -expectType>( - await client.withAllLocales.getEntry('entry-id'), + +expectType>( + await client.withAllLocales.getEntry('entry-id'), ) -expectType>( + +expectType>( await client.withAllLocales.getEntries(), ) -expectType>( - await client.withAllLocales.getEntries(), + +expectType>( + await client.withAllLocales.getEntries(), +) + +expectType>( + await client.withAllLocales.getEntries(), +) + +expectType>( + (await client.withAllLocales.getEntries()).includes!.Entry![0], ) -expectType>( - await client.withAllLocales.getEntries(), + +expectType>( + (await client.withAllLocales.getEntries()).includes!.Entry![0], ) -expectType>( +/** + * With all Locales and without unresolvable Links + */ +expectType>( await client.withAllLocales.withoutUnresolvableLinks.getEntry('entry-id'), ) -expectType>( - await client.withAllLocales.withoutUnresolvableLinks.getEntry('entry-id'), + +expectType>( + await client.withAllLocales.withoutUnresolvableLinks.getEntry('entry-id'), ) -expectType>( - await client.withAllLocales.withoutUnresolvableLinks.getEntry('entry-id'), + +expectType>( + await client.withAllLocales.withoutUnresolvableLinks.getEntry( + 'entry-id', + ), ) -expectType>( + +expectType>( await client.withAllLocales.withoutUnresolvableLinks.getEntries(), ) -expectType>( - await client.withAllLocales.withoutUnresolvableLinks.getEntries(), + +expectType>( + await client.withAllLocales.withoutUnresolvableLinks.getEntries(), ) + expectType< - EntryCollection ->(await client.withAllLocales.withoutUnresolvableLinks.getEntries()) + EntryCollection +>(await client.withAllLocales.withoutUnresolvableLinks.getEntries()) -expectType>( +expectType>( + (await client.withAllLocales.withoutUnresolvableLinks.getEntries()).includes! + .Entry![0], +) + +expectType>( + (await client.withAllLocales.withoutUnresolvableLinks.getEntries()) + .includes!.Entry![0], +) + +/** + * With all Locales and without link resolution + */ +expectType>( await client.withAllLocales.withoutLinkResolution.getEntry('entry-id'), ) -expectType>( - await client.withAllLocales.withoutLinkResolution.getEntry('entry-id'), + +expectType>( + await client.withAllLocales.withoutLinkResolution.getEntry('entry-id'), ) -expectType>( - await client.withAllLocales.withoutLinkResolution.getEntry('entry-id'), + +expectType>( + await client.withAllLocales.withoutLinkResolution.getEntry('entry-id'), ) -expectType>( + +expectType>( await client.withAllLocales.withoutLinkResolution.getEntries(), ) -expectType>( - await client.withAllLocales.withoutLinkResolution.getEntries(), + +expectType>( + await client.withAllLocales.withoutLinkResolution.getEntries(), +) + +expectType< + EntryCollection +>(await client.withAllLocales.withoutLinkResolution.getEntries()) + +expectType>( + (await client.withAllLocales.withoutLinkResolution.getEntries()).includes!.Entry![0], ) -expectType>( - await client.withAllLocales.withoutLinkResolution.getEntries(), + +expectType>( + (await client.withAllLocales.withoutLinkResolution.getEntries()) + .includes!.Entry![0], )