@@ -653,6 +653,7 @@ const typeLiteralConverter: TypeConverter<ts.TypeLiteralNode> = {
653653 return new ReflectionType ( reflection ) ;
654654 } ,
655655 convertType ( context , type ) {
656+ // Don't use the third parameter here or you break convertTypeInline
656657 const symbol = type . getSymbol ( ) ;
657658 const reflection = new DeclarationReflection (
658659 "__type" ,
@@ -764,16 +765,7 @@ const referenceConverter: TypeConverter<
764765 ! node . typeArguments &&
765766 context . shouldInline ( symbol , name )
766767 ) {
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 ) ;
777769 }
778770
779771 const ref = context . createSymbolReference (
@@ -808,16 +800,7 @@ const referenceConverter: TypeConverter<
808800 }
809801
810802 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 ) ;
821804 }
822805
823806 const ref = context . createSymbolReference (
@@ -1259,3 +1242,36 @@ function normalizeUnion(types: SomeType[]) {
12591242 ) ;
12601243 }
12611244}
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