Skip to content

Commit 009c04f

Browse files
author
naman-contentstack
committed
refactor based on comments
1 parent b8eb412 commit 009c04f

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

src/generateTS/factory.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -527,29 +527,25 @@ export default function (userOptions: TSGenOptions) {
527527
return "Record<string, unknown>[]";
528528
}
529529

530-
// Conditionally use the ReferencedEntry interface from builtins
530+
// Handle reference types with or without ReferencedEntry interface
531531
if (options.includeReferencedEntry) {
532532
const referencedEntryType = `${options.naming?.prefix || ""}ReferencedEntry`;
533533

534-
// If there's only one reference type, create a simple union
535-
if (references.length === 1) {
536-
return `(${references[0]} | ${referencedEntryType})[]`;
537-
}
534+
const wrapWithReferencedEntry = (refType: string) =>
535+
`(${refType} | ${referencedEntryType})`;
538536

539-
// If there are multiple reference types, create separate unions for each
540-
const unionTypes = references.map((refType) => {
541-
return `(${refType} | ${referencedEntryType})`;
542-
});
537+
const types =
538+
references.length === 1
539+
? wrapWithReferencedEntry(references[0])
540+
: references.map(wrapWithReferencedEntry).join(" | ");
543541

544-
return `${unionTypes.join(" | ")}[]`;
545-
} else {
546-
// If ReferencedEntry is disabled, just use the reference types directly
547-
if (references.length === 1) {
548-
return `${references[0]}[]`;
549-
}
550-
551-
return `${references.join(" | ")}[]`;
542+
return `${types}[]`;
552543
}
544+
545+
const baseType =
546+
references.length === 1 ? references[0] : references.join(" | ");
547+
548+
return `${baseType}[]`;
553549
}
554550

555551
return function (

0 commit comments

Comments
 (0)