@@ -544,55 +544,53 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
544544 }
545545
546546 // additionalProperties / patternProperties
547- if ( schemaObject . additionalProperties || options . ctx . additionalProperties || schemaObject . patternProperties ) {
548- const hasExplicitAdditionalProperties =
549- typeof schemaObject . additionalProperties === "object" && Object . keys ( schemaObject . additionalProperties ) . length ;
550- const hasImplicitAdditionalProperties =
551- schemaObject . additionalProperties === true ||
552- ( typeof schemaObject . additionalProperties === "object" &&
553- Object . keys ( schemaObject . additionalProperties ) . length === 0 ) ;
554- const hasExplicitPatternProperties =
555- typeof schemaObject . patternProperties === "object" && Object . keys ( schemaObject . patternProperties ) . length ;
556- const addlTypes = [ ] ;
557- if ( hasExplicitAdditionalProperties ) {
558- addlTypes . push ( transformSchemaObject ( schemaObject . additionalProperties as SchemaObject , options ) ) ;
559- }
560- if ( hasImplicitAdditionalProperties || ( ! schemaObject . additionalProperties && options . ctx . additionalProperties ) ) {
561- addlTypes . push ( UNKNOWN ) ;
562- }
563- if ( hasExplicitPatternProperties ) {
564- for ( const [ _ , v ] of getEntries ( schemaObject . patternProperties ?? { } , options . ctx ) ) {
565- addlTypes . push ( transformSchemaObject ( v , options ) ) ;
566- }
567- }
568-
569- if ( addlTypes . length === 0 ) {
570- return ;
547+ const hasExplicitAdditionalProperties =
548+ typeof schemaObject . additionalProperties === "object" && Object . keys ( schemaObject . additionalProperties ) . length ;
549+ const hasImplicitAdditionalProperties =
550+ schemaObject . additionalProperties === true ||
551+ ( typeof schemaObject . additionalProperties === "object" &&
552+ Object . keys ( schemaObject . additionalProperties ) . length === 0 ) ;
553+ const hasExplicitPatternProperties =
554+ typeof schemaObject . patternProperties === "object" && Object . keys ( schemaObject . patternProperties ) . length ;
555+ const stringIndexTypes = [ ] ;
556+ if ( hasExplicitAdditionalProperties ) {
557+ stringIndexTypes . push ( transformSchemaObject ( schemaObject . additionalProperties as SchemaObject , options ) ) ;
558+ }
559+ if ( hasImplicitAdditionalProperties || ( ! schemaObject . additionalProperties && options . ctx . additionalProperties ) ) {
560+ stringIndexTypes . push ( UNKNOWN ) ;
561+ }
562+ if ( hasExplicitPatternProperties ) {
563+ for ( const [ _ , v ] of getEntries ( schemaObject . patternProperties ?? { } , options . ctx ) ) {
564+ stringIndexTypes . push ( transformSchemaObject ( v , options ) ) ;
571565 }
566+ }
572567
573- const addlType = tsUnion ( addlTypes ) ;
574-
575- return tsIntersection ( [
576- ...( coreObjectType . length ? [ ts . factory . createTypeLiteralNode ( coreObjectType ) ] : [ ] ) ,
577- ts . factory . createTypeLiteralNode ( [
578- ts . factory . createIndexSignature (
579- /* modifiers */ tsModifiers ( {
580- readonly : options . ctx . immutable ,
581- } ) ,
582- /* parameters */ [
583- ts . factory . createParameterDeclaration (
584- /* modifiers */ undefined ,
585- /* dotDotDotToken */ undefined ,
586- /* name */ ts . factory . createIdentifier ( "key" ) ,
587- /* questionToken */ undefined ,
588- /* type */ STRING ,
589- ) ,
590- ] ,
591- /* type */ addlType ,
592- ) ,
593- ] ) ,
594- ] ) ;
568+ if ( stringIndexTypes . length === 0 ) {
569+ return coreObjectType . length ? ts . factory . createTypeLiteralNode ( coreObjectType ) : undefined ;
595570 }
571+
572+ const stringIndexType = tsUnion ( stringIndexTypes ) ;
573+
574+ return tsIntersection ( [
575+ ...( coreObjectType . length ? [ ts . factory . createTypeLiteralNode ( coreObjectType ) ] : [ ] ) ,
576+ ts . factory . createTypeLiteralNode ( [
577+ ts . factory . createIndexSignature (
578+ /* modifiers */ tsModifiers ( {
579+ readonly : options . ctx . immutable ,
580+ } ) ,
581+ /* parameters */ [
582+ ts . factory . createParameterDeclaration (
583+ /* modifiers */ undefined ,
584+ /* dotDotDotToken */ undefined ,
585+ /* name */ ts . factory . createIdentifier ( "key" ) ,
586+ /* questionToken */ undefined ,
587+ /* type */ STRING ,
588+ ) ,
589+ ] ,
590+ /* type */ stringIndexType ,
591+ ) ,
592+ ] ) ,
593+ ] ) ;
596594 }
597595
598596 return coreObjectType . length ? ts . factory . createTypeLiteralNode ( coreObjectType ) : undefined ;
0 commit comments