@@ -174,31 +174,23 @@ export default function (userOptions: TSGenOptions) {
174174 // Validate the interface name before creating it
175175 let interfaceName : string ;
176176
177- if ( contentType . data_type === "global_field" ) {
178- const referenceTo = contentType . reference_to as string ;
179- if ( isNumericIdentifier ( referenceTo ) ) {
180- throwUIDValidationError ( {
181- uid : contentType . uid ,
182- errorCode : "INVALID_GLOBAL_FIELD_REFERENCE" ,
183- reason : NUMERIC_IDENTIFIER_EXCLUSION_REASON ,
184- suggestion : `Since UIDs cannot be changed, use the --prefix flag to add a valid prefix to all interface names (e.g., --prefix "ContentType")` ,
185- context : "generateTSFromContentTypes" ,
186- referenceTo,
187- } ) ;
188- }
189- interfaceName = name_type ( referenceTo ) ;
190- } else {
191- if ( isNumericIdentifier ( contentType . uid ) ) {
192- throwUIDValidationError ( {
193- uid : contentType . uid ,
194- errorCode : "INVALID_CONTENT_TYPE_UID" ,
195- reason : NUMERIC_IDENTIFIER_EXCLUSION_REASON ,
196- suggestion : `Since UIDs cannot be changed, use the --prefix flag to add a valid prefix to all interface names (e.g., --prefix "ContentType")` ,
197- context : "generateTSFromContentTypes" ,
198- } ) ;
199- }
200- interfaceName = name_type ( contentType . uid ) ;
177+ const isGlobalField = contentType . data_type === "global_field" ;
178+ const identifier = isGlobalField
179+ ? ( contentType . reference_to as string )
180+ : contentType . uid ;
181+ if ( isNumericIdentifier ( identifier ) ) {
182+ throwUIDValidationError ( {
183+ uid : contentType . uid ,
184+ errorCode : isGlobalField
185+ ? "INVALID_GLOBAL_FIELD_REFERENCE"
186+ : "INVALID_CONTENT_TYPE_UID" ,
187+ reason : NUMERIC_IDENTIFIER_EXCLUSION_REASON ,
188+ suggestion : `Since UIDs cannot be changed, use the --prefix flag to add a valid prefix to all interface names (e.g., --prefix "ContentType")` ,
189+ context : "generateTSFromContentTypes" ,
190+ ...( isGlobalField && { referenceTo : identifier } ) ,
191+ } ) ;
201192 }
193+ interfaceName = name_type ( identifier ) ;
202194
203195 const interface_declaration = [ "export interface" , interfaceName ] ;
204196 if ( systemFields && contentType . schema_type !== "global_field" ) {
0 commit comments