@@ -653,6 +653,7 @@ const typeLiteralConverter: TypeConverter<ts.TypeLiteralNode> = {
653
653
return new ReflectionType ( reflection ) ;
654
654
} ,
655
655
convertType ( context , type ) {
656
+ // Don't use the third parameter here or you break convertTypeInline
656
657
const symbol = type . getSymbol ( ) ;
657
658
const reflection = new DeclarationReflection (
658
659
"__type" ,
@@ -764,16 +765,7 @@ const referenceConverter: TypeConverter<
764
765
! node . typeArguments &&
765
766
context . shouldInline ( symbol , name )
766
767
) {
767
- // typeLiteralConverter doesn't use the node, so we can get away with lying here.
768
- // This might not actually be safe, it appears that it is in the relatively small
769
- // amount of testing I've done with it, but I wouldn't be surprised if someone manages
770
- // to find a crash.
771
- return typeLiteralConverter . convertType (
772
- context ,
773
- type ,
774
- null ! ,
775
- undefined ,
776
- ) ;
768
+ return convertTypeInlined ( context , type ) ;
777
769
}
778
770
779
771
const ref = context . createSymbolReference (
@@ -808,16 +800,7 @@ const referenceConverter: TypeConverter<
808
800
}
809
801
810
802
if ( context . shouldInline ( symbol , name ) ) {
811
- // typeLiteralConverter doesn't use the node, so we can get away with lying here.
812
- // This might not actually be safe, it appears that it is in the relatively small
813
- // amount of testing I've done with it, but I wouldn't be surprised if someone manages
814
- // to find a crash.
815
- return typeLiteralConverter . convertType (
816
- context ,
817
- type ,
818
- null ! ,
819
- undefined ,
820
- ) ;
803
+ return convertTypeInlined ( context , type ) ;
821
804
}
822
805
823
806
const ref = context . createSymbolReference (
@@ -1259,3 +1242,36 @@ function normalizeUnion(types: SomeType[]) {
1259
1242
) ;
1260
1243
}
1261
1244
}
1245
+
1246
+ function convertTypeInlined ( context : Context , type : ts . Type ) : SomeType {
1247
+ if ( type . isUnion ( ) ) {
1248
+ const types = type . types . map ( type => convertType ( context , type ) ) ;
1249
+ return new UnionType ( types ) ;
1250
+ }
1251
+
1252
+ if ( type . isIntersection ( ) ) {
1253
+ const types = type . types . map ( type => convertType ( context , type ) ) ;
1254
+ return new IntersectionType ( types ) ;
1255
+ }
1256
+
1257
+ if ( type . isLiteral ( ) ) {
1258
+ return new LiteralType (
1259
+ typeof type . value === "object"
1260
+ ? BigInt ( type . value . base10Value ) * ( type . value . negative ? - 1n : 1n )
1261
+ : type . value ,
1262
+ ) ;
1263
+ }
1264
+
1265
+ if ( context . checker . isArrayType ( type ) ) {
1266
+ const elementType = convertType ( context , context . checker . getTypeArguments ( type as ts . TypeReference ) [ 0 ] ) ;
1267
+ return new ArrayType ( elementType ) ;
1268
+ }
1269
+
1270
+ // typeLiteralConverter doesn't use the node, so we can get away with lying here.
1271
+ return typeLiteralConverter . convertType (
1272
+ context ,
1273
+ type ,
1274
+ null ! ,
1275
+ undefined ,
1276
+ ) ;
1277
+ }
0 commit comments