@@ -1390,9 +1390,11 @@ function buildSchemaReference(
1390
1390
getDependencyName : Required < GenerateZodSchemaProps > [ "getDependencyName" ] ;
1391
1391
} ,
1392
1392
path = ""
1393
- ) : ts . PropertyAccessExpression | ts . Identifier {
1393
+ ) : ts . PropertyAccessExpression | ts . Identifier | ts . ElementAccessExpression {
1394
1394
const indexTypeText = node . indexType . getText ( sourceFile ) ;
1395
- const { indexTypeName, type : indexTypeType } = / ^ " \w + " $ / . exec ( indexTypeText )
1395
+ const { indexTypeName, type : indexTypeType } = / ^ [ ' " ] ( [ ^ ' " ] + ) [ ' " ] $ / . exec (
1396
+ indexTypeText
1397
+ )
1396
1398
? { type : "string" as const , indexTypeName : indexTypeText . slice ( 1 , - 1 ) }
1397
1399
: { type : "number" as const , indexTypeName : indexTypeText } ;
1398
1400
@@ -1496,9 +1498,19 @@ function buildSchemaReference(
1496
1498
node . objectType . typeName . getText ( sourceFile )
1497
1499
) ;
1498
1500
dependencies . push ( dependencyName ) ;
1499
- return f . createPropertyAccessExpression (
1500
- f . createIdentifier ( dependencyName ) ,
1501
- f . createIdentifier ( `shape.${ indexTypeName } .${ path } ` . slice ( 0 , - 1 ) )
1501
+
1502
+ if ( / ^ [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ $ ] * $ / . test ( indexTypeName ) ) {
1503
+ return f . createPropertyAccessExpression (
1504
+ f . createIdentifier ( dependencyName ) ,
1505
+ f . createIdentifier ( `shape.${ indexTypeName } .${ path } ` . slice ( 0 , - 1 ) )
1506
+ ) ;
1507
+ }
1508
+ return f . createElementAccessExpression (
1509
+ f . createPropertyAccessExpression (
1510
+ f . createIdentifier ( dependencyName ) ,
1511
+ f . createIdentifier ( "shape" )
1512
+ ) ,
1513
+ f . createStringLiteral ( indexTypeName )
1502
1514
) ;
1503
1515
}
1504
1516
0 commit comments