Skip to content

Commit f9bf2cc

Browse files
authored
feat: give includes basic entry and asset types instead of any (#2363)
1 parent f926c4e commit f9bf2cc

File tree

2 files changed

+141
-54
lines changed

2 files changed

+141
-54
lines changed

lib/types/entry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export type EntryCollection<
339339
> = ContentfulCollection<Entry<EntrySkeleton, Modifiers, Locales>> & {
340340
errors?: Array<any>
341341
includes?: {
342-
Entry?: any[]
343-
Asset?: any[]
342+
Entry?: Entry<EntrySkeletonType, Modifiers, Locales>[]
343+
Asset?: Asset<Modifiers, Locales>[]
344344
}
345345
}

test/types/client/getEntries.test-d.ts

Lines changed: 139 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,105 +18,192 @@ type Fields = {
1818
moreLinks: Entry<LinkedSkeleton>[]
1919
}
2020

21-
type EntrySkeleton = EntrySkeletonType<Fields, 'content-type-id'>
21+
// A skeleton with no fields
22+
type BaseEntrySkeleton = EntrySkeletonType
23+
24+
// Skeleton with some specific fields
25+
type TestEntrySkeleton = EntrySkeletonType<Fields, 'content-type-id'>
2226

2327
type Locale = 'en'
2428

25-
expectType<Entry<EntrySkeleton, undefined>>(await client.getEntry('entry-id'))
26-
expectType<Entry<EntrySkeleton, undefined>>(await client.getEntry<EntrySkeleton>('entry-id'))
27-
expectType<EntryCollection<EntrySkeleton, undefined>>(await client.getEntries())
28-
expectType<EntryCollection<EntrySkeleton, undefined>>(await client.getEntries<EntrySkeleton>())
29+
/**
30+
* With no extra parameters
31+
*/
32+
expectType<Entry<TestEntrySkeleton, undefined>>(await client.getEntry('entry-id'))
33+
34+
expectType<Entry<TestEntrySkeleton, undefined>>(
35+
await client.getEntry<TestEntrySkeleton>('entry-id'),
36+
)
37+
expectType<EntryCollection<TestEntrySkeleton, undefined>>(await client.getEntries())
38+
39+
expectType<EntryCollection<TestEntrySkeleton, undefined>>(
40+
await client.getEntries<TestEntrySkeleton>(),
41+
)
42+
expectType<Entry<BaseEntrySkeleton, undefined>>((await client.getEntries()).includes!.Entry![0])
2943

30-
expectType<EntryCollection<EntrySkeleton, undefined>>(
31-
await client.getEntries<EntrySkeleton>({ content_type: 'content-type-id' }),
44+
expectType<EntryCollection<TestEntrySkeleton, undefined>>(
45+
await client.getEntries<TestEntrySkeleton>({ content_type: 'content-type-id' }),
3246
)
3347

34-
expectError(await client.getEntries<EntrySkeleton>({ content_type: 'unexpected' }))
35-
expectType<EntryCollection<EntrySkeleton | LinkedSkeleton, undefined>>(
36-
await client.getEntries<EntrySkeleton | LinkedSkeleton>({
48+
expectError(await client.getEntries<TestEntrySkeleton>({ content_type: 'unexpected' }))
49+
50+
expectType<EntryCollection<TestEntrySkeleton | LinkedSkeleton, undefined>>(
51+
await client.getEntries<TestEntrySkeleton | LinkedSkeleton>({
3752
content_type: 'content-type-id',
3853
}),
3954
)
4055

41-
expectType<Entry<EntrySkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>(
56+
/**
57+
* Without unresolvable Links
58+
*/
59+
expectType<Entry<TestEntrySkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>(
4260
await client.withoutUnresolvableLinks.getEntry('entry-id'),
4361
)
44-
expectType<Entry<EntrySkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>(
45-
await client.withoutUnresolvableLinks.getEntry<EntrySkeleton>('entry-id'),
62+
expectType<Entry<TestEntrySkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>(
63+
await client.withoutUnresolvableLinks.getEntry<TestEntrySkeleton>('entry-id'),
4664
)
47-
expectType<EntryCollection<EntrySkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>(
65+
66+
expectType<EntryCollection<TestEntrySkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>(
4867
await client.withoutUnresolvableLinks.getEntries(),
4968
)
50-
expectType<EntryCollection<EntrySkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>(
51-
await client.withoutUnresolvableLinks.getEntries<EntrySkeleton>(),
69+
70+
expectType<EntryCollection<TestEntrySkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>(
71+
await client.withoutUnresolvableLinks.getEntries<TestEntrySkeleton>(),
5272
)
5373

54-
expectType<Entry<EntrySkeleton, 'WITHOUT_LINK_RESOLUTION'>>(
74+
expectType<Entry<BaseEntrySkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>(
75+
(await client.withoutUnresolvableLinks.getEntries()).includes!.Entry![0],
76+
)
77+
78+
/**
79+
* Without link resolution
80+
*/
81+
expectType<Entry<TestEntrySkeleton, 'WITHOUT_LINK_RESOLUTION'>>(
5582
await client.withoutLinkResolution.getEntry('entry-id'),
5683
)
57-
expectType<Entry<EntrySkeleton, 'WITHOUT_LINK_RESOLUTION'>>(
58-
await client.withoutLinkResolution.getEntry<EntrySkeleton>('entry-id'),
84+
85+
expectType<Entry<TestEntrySkeleton, 'WITHOUT_LINK_RESOLUTION'>>(
86+
await client.withoutLinkResolution.getEntry<TestEntrySkeleton>('entry-id'),
5987
)
60-
expectType<EntryCollection<EntrySkeleton, 'WITHOUT_LINK_RESOLUTION'>>(
88+
89+
expectType<EntryCollection<TestEntrySkeleton, 'WITHOUT_LINK_RESOLUTION'>>(
6190
await client.withoutLinkResolution.getEntries(),
6291
)
63-
expectType<EntryCollection<EntrySkeleton, 'WITHOUT_LINK_RESOLUTION'>>(
64-
await client.withoutLinkResolution.getEntries<EntrySkeleton>(),
92+
93+
expectType<EntryCollection<TestEntrySkeleton, 'WITHOUT_LINK_RESOLUTION'>>(
94+
await client.withoutLinkResolution.getEntries<TestEntrySkeleton>(),
6595
)
6696

67-
expectType<Entry<EntrySkeleton, 'WITH_ALL_LOCALES'>>(
97+
expectType<Entry<BaseEntrySkeleton, 'WITHOUT_LINK_RESOLUTION'>>(
98+
(await client.withoutLinkResolution.getEntries()).includes!.Entry![0],
99+
)
100+
101+
/**
102+
* With all Locales
103+
*/
104+
expectType<Entry<TestEntrySkeleton, 'WITH_ALL_LOCALES'>>(
68105
await client.withAllLocales.getEntry('entry-id'),
69106
)
70-
expectType<Entry<EntrySkeleton, 'WITH_ALL_LOCALES'>>(
71-
await client.withAllLocales.getEntry<EntrySkeleton>('entry-id'),
107+
108+
expectType<Entry<TestEntrySkeleton, 'WITH_ALL_LOCALES'>>(
109+
await client.withAllLocales.getEntry<TestEntrySkeleton>('entry-id'),
72110
)
73-
expectType<Entry<EntrySkeleton, 'WITH_ALL_LOCALES', Locale>>(
74-
await client.withAllLocales.getEntry<EntrySkeleton, Locale>('entry-id'),
111+
112+
expectType<Entry<TestEntrySkeleton, 'WITH_ALL_LOCALES', Locale>>(
113+
await client.withAllLocales.getEntry<TestEntrySkeleton, Locale>('entry-id'),
75114
)
76-
expectType<EntryCollection<EntrySkeleton, 'WITH_ALL_LOCALES'>>(
115+
116+
expectType<EntryCollection<TestEntrySkeleton, 'WITH_ALL_LOCALES'>>(
77117
await client.withAllLocales.getEntries(),
78118
)
79-
expectType<EntryCollection<EntrySkeleton, 'WITH_ALL_LOCALES'>>(
80-
await client.withAllLocales.getEntries<EntrySkeleton>(),
119+
120+
expectType<EntryCollection<TestEntrySkeleton, 'WITH_ALL_LOCALES'>>(
121+
await client.withAllLocales.getEntries<TestEntrySkeleton>(),
122+
)
123+
124+
expectType<EntryCollection<TestEntrySkeleton, 'WITH_ALL_LOCALES', Locale>>(
125+
await client.withAllLocales.getEntries<TestEntrySkeleton, Locale>(),
126+
)
127+
128+
expectType<Entry<BaseEntrySkeleton, 'WITH_ALL_LOCALES', Locale>>(
129+
(await client.withAllLocales.getEntries<TestEntrySkeleton, Locale>()).includes!.Entry![0],
81130
)
82-
expectType<EntryCollection<EntrySkeleton, 'WITH_ALL_LOCALES', Locale>>(
83-
await client.withAllLocales.getEntries<EntrySkeleton, Locale>(),
131+
132+
expectType<Entry<BaseEntrySkeleton, 'WITH_ALL_LOCALES'>>(
133+
(await client.withAllLocales.getEntries<TestEntrySkeleton>()).includes!.Entry![0],
84134
)
85135

86-
expectType<Entry<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS'>>(
136+
/**
137+
* With all Locales and without unresolvable Links
138+
*/
139+
expectType<Entry<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS'>>(
87140
await client.withAllLocales.withoutUnresolvableLinks.getEntry('entry-id'),
88141
)
89-
expectType<Entry<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS'>>(
90-
await client.withAllLocales.withoutUnresolvableLinks.getEntry<EntrySkeleton>('entry-id'),
142+
143+
expectType<Entry<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS'>>(
144+
await client.withAllLocales.withoutUnresolvableLinks.getEntry<TestEntrySkeleton>('entry-id'),
91145
)
92-
expectType<Entry<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS', Locale>>(
93-
await client.withAllLocales.withoutUnresolvableLinks.getEntry<EntrySkeleton, Locale>('entry-id'),
146+
147+
expectType<Entry<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS', Locale>>(
148+
await client.withAllLocales.withoutUnresolvableLinks.getEntry<TestEntrySkeleton, Locale>(
149+
'entry-id',
150+
),
94151
)
95-
expectType<EntryCollection<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS'>>(
152+
153+
expectType<EntryCollection<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS'>>(
96154
await client.withAllLocales.withoutUnresolvableLinks.getEntries(),
97155
)
98-
expectType<EntryCollection<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS'>>(
99-
await client.withAllLocales.withoutUnresolvableLinks.getEntries<EntrySkeleton>(),
156+
157+
expectType<EntryCollection<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS'>>(
158+
await client.withAllLocales.withoutUnresolvableLinks.getEntries<TestEntrySkeleton>(),
100159
)
160+
101161
expectType<
102-
EntryCollection<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS', Locale>
103-
>(await client.withAllLocales.withoutUnresolvableLinks.getEntries<EntrySkeleton, Locale>())
162+
EntryCollection<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS', Locale>
163+
>(await client.withAllLocales.withoutUnresolvableLinks.getEntries<TestEntrySkeleton, Locale>())
104164

105-
expectType<Entry<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION'>>(
165+
expectType<Entry<BaseEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS'>>(
166+
(await client.withAllLocales.withoutUnresolvableLinks.getEntries<TestEntrySkeleton>()).includes!
167+
.Entry![0],
168+
)
169+
170+
expectType<Entry<BaseEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_UNRESOLVABLE_LINKS', Locale>>(
171+
(await client.withAllLocales.withoutUnresolvableLinks.getEntries<TestEntrySkeleton, Locale>())
172+
.includes!.Entry![0],
173+
)
174+
175+
/**
176+
* With all Locales and without link resolution
177+
*/
178+
expectType<Entry<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION'>>(
106179
await client.withAllLocales.withoutLinkResolution.getEntry('entry-id'),
107180
)
108-
expectType<Entry<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION'>>(
109-
await client.withAllLocales.withoutLinkResolution.getEntry<EntrySkeleton>('entry-id'),
181+
182+
expectType<Entry<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION'>>(
183+
await client.withAllLocales.withoutLinkResolution.getEntry<TestEntrySkeleton>('entry-id'),
110184
)
111-
expectType<Entry<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION', Locale>>(
112-
await client.withAllLocales.withoutLinkResolution.getEntry<EntrySkeleton, Locale>('entry-id'),
185+
186+
expectType<Entry<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION', Locale>>(
187+
await client.withAllLocales.withoutLinkResolution.getEntry<TestEntrySkeleton, Locale>('entry-id'),
113188
)
114-
expectType<EntryCollection<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION'>>(
189+
190+
expectType<EntryCollection<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION'>>(
115191
await client.withAllLocales.withoutLinkResolution.getEntries(),
116192
)
117-
expectType<EntryCollection<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION'>>(
118-
await client.withAllLocales.withoutLinkResolution.getEntries<EntrySkeleton>(),
193+
194+
expectType<EntryCollection<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION'>>(
195+
await client.withAllLocales.withoutLinkResolution.getEntries<TestEntrySkeleton>(),
196+
)
197+
198+
expectType<
199+
EntryCollection<TestEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION', Locale>
200+
>(await client.withAllLocales.withoutLinkResolution.getEntries<TestEntrySkeleton, Locale>())
201+
202+
expectType<Entry<BaseEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION'>>(
203+
(await client.withAllLocales.withoutLinkResolution.getEntries()).includes!.Entry![0],
119204
)
120-
expectType<EntryCollection<EntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION', Locale>>(
121-
await client.withAllLocales.withoutLinkResolution.getEntries<EntrySkeleton, Locale>(),
205+
206+
expectType<Entry<BaseEntrySkeleton, 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION', Locale>>(
207+
(await client.withAllLocales.withoutLinkResolution.getEntries<TestEntrySkeleton, Locale>())
208+
.includes!.Entry![0],
122209
)

0 commit comments

Comments
 (0)