Skip to content

Commit 9f834ed

Browse files
committed
refactor: more be specific stuff
1 parent 646e85b commit 9f834ed

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/cf-definitions-builder.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,26 @@ export default class CFDefinitionsBuilder {
199199
declaration: InterfaceDeclaration,
200200
field: Field,
201201
): void => {
202+
const type = renderProp(field);
202203
declaration.addProperty({
203204
name: field.id,
204205
hasQuestionToken: field.omitted || (!field.required),
205-
type: renderProp(field),
206+
type,
206207
});
207208

208-
// eslint-disable-next-line no-warning-comments
209-
// TODO: dynamically define imports based on usage
210-
file.addImportDeclaration({
211-
moduleSpecifier: 'contentful',
212-
namespaceImport: 'Contentful',
213-
});
209+
if (type.includes('Contentful.')) {
210+
file.addImportDeclaration({
211+
moduleSpecifier: 'contentful',
212+
namespaceImport: 'Contentful',
213+
});
214+
}
215+
216+
if (type.includes('EntryLink')) {
217+
file.addImportDeclaration({
218+
moduleSpecifier: '@src/types/contentful/static',
219+
namedImports: ['EntryLink'],
220+
});
221+
}
214222

215223
file.addImportDeclaration({
216224
moduleSpecifier: '@contentful/rich-text-types',

src/renderer/cf-render-prop-link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {renderUnionType} from './render-union-type';
44

55
const linkContentType = (field: Pick<Field, 'validations'>): string => {
66
const validations = linkContentTypeValidations(field);
7-
return validations?.length > 0 ? renderUnionType(validations.map(moduleName)) : 'CMSEntries';
7+
return validations?.length > 0 ? renderUnionType(validations.map(name => `EntryLink<${moduleName(name)}>`)) : 'EntryLink';
88
};
99

1010
export const renderPropLink = (field: Pick<Field, 'validations' | 'linkType'>) => {

0 commit comments

Comments
 (0)