@@ -38,7 +38,7 @@ import {
38
38
createSignature ,
39
39
} from "./factories/signature.js" ;
40
40
import { convertSymbol } from "./symbols.js" ;
41
- import { isObjectType } from "./utils/nodes.js" ;
41
+ import { isObjectType , isTypeReference } from "./utils/nodes.js" ;
42
42
import { removeUndefined } from "./utils/reflections.js" ;
43
43
import type { TranslatedString } from "../internationalization/internationalization.js" ;
44
44
@@ -813,6 +813,7 @@ const referenceConverter: TypeConverter<
813
813
context ,
814
814
name ,
815
815
) ;
816
+
816
817
if ( type . flags & ts . TypeFlags . Substitution ) {
817
818
// NoInfer<T>
818
819
ref . typeArguments = [
@@ -823,11 +824,24 @@ const referenceConverter: TypeConverter<
823
824
convertType ( context , ( type as ts . StringMappingType ) . type ) ,
824
825
] ;
825
826
} else {
826
- ref . typeArguments = (
827
- type . aliasSymbol
828
- ? type . aliasTypeArguments
829
- : ( type as ts . TypeReference ) . typeArguments
830
- ) ?. map ( ( ref ) => convertType ( context , ref ) ) ;
827
+ // Default type arguments are filled with a reference to the default
828
+ // type. As TS doesn't support specifying earlier defaults, we know
829
+ // that this will only filter out type arguments which aren't specified
830
+ // by the user.
831
+ let ignoredArgs : ts . Type [ ] | undefined ;
832
+ if ( isTypeReference ( type ) ) {
833
+ ignoredArgs = type . target . typeParameters
834
+ ?. map ( ( p ) => p . getDefault ( ) )
835
+ . filter ( ( x ) => ! ! x ) ;
836
+ }
837
+
838
+ const args = type . aliasSymbol
839
+ ? type . aliasTypeArguments
840
+ : ( type as ts . TypeReference ) . typeArguments ;
841
+
842
+ ref . typeArguments = args
843
+ ?. filter ( ( ref ) => ! ignoredArgs ?. includes ( ref ) )
844
+ . map ( ( ref ) => convertType ( context , ref ) ) ;
831
845
}
832
846
return ref ;
833
847
} ,
0 commit comments