Skip to content

Commit 63ed374

Browse files
authored
Add IEntry type (#128)
1 parent 04d3bd9 commit 63ed374

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/renderers/render.ts

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import renderAllLocales from "./contentful/renderAllLocales"
99
import renderDefaultLocale from "./contentful/renderDefaultLocale"
1010
import renderNamespace from "./contentful/renderNamespace"
1111
import renderLocalizedTypes from "./contentful/renderLocalizedTypes"
12+
import renderContentTypeId from "./contentful/renderContentTypeId"
1213

1314
interface Options {
1415
localization?: boolean
@@ -26,6 +27,7 @@ export default async function render(
2627
const typingsSource = [
2728
renderAllContentTypes(sortedContentTypes, localization),
2829
renderAllContentTypeIds(sortedContentTypes),
30+
renderEntryType(sortedContentTypes),
2931
renderAllLocales(sortedLocales),
3032
renderDefaultLocale(sortedLocales),
3133
renderLocalizedTypes(localization),
@@ -50,3 +52,10 @@ function renderAllContentTypeIds(contentTypes: ContentType[]): string {
5052
contentTypes.map(contentType => `'${contentType.sys.id}'`),
5153
)
5254
}
55+
56+
function renderEntryType(contentTypes: ContentType[]) {
57+
return renderUnion(
58+
"IEntry",
59+
contentTypes.map(contentType => renderContentTypeId(contentType.sys.id)),
60+
)
61+
}

test/renderers/render.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ describe("render()", () => {
8282
8383
export type CONTENT_TYPE = \\"myContentType\\"
8484
85+
export type IEntry = IMyContentType
86+
8587
export type LOCALE_CODE = \\"en-US\\" | \\"pt-BR\\"
8688
8789
export type CONTENTFUL_DEFAULT_LOCALE_CODE = \\"en-US\\"
@@ -152,6 +154,8 @@ describe("render()", () => {
152154
153155
export type CONTENT_TYPE = \\"myContentType\\"
154156
157+
export type IEntry = IMyContentType
158+
155159
export type LOCALE_CODE = \\"en-US\\" | \\"pt-BR\\"
156160
157161
export type CONTENTFUL_DEFAULT_LOCALE_CODE = \\"en-US\\"
@@ -215,6 +219,8 @@ describe("render()", () => {
215219
216220
export type CONTENT_TYPE = \\"myContentType\\"
217221
222+
export type IEntry = IMyContentType
223+
218224
export type LOCALE_CODE = \\"en-US\\" | \\"pt-BR\\"
219225
220226
export type CONTENTFUL_DEFAULT_LOCALE_CODE = \\"en-US\\"

0 commit comments

Comments
 (0)