You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The changes in #2820 have a couple of shortcomings. The new logic removes a type argument if it matches the default value of any type parameter. What we have to do is work from the last type argument backwards and check each one in turn for whether it matches the default. We need to include all arguments before the last nondefault argument even if they are defaults.
The following patch mostly fixes it, though it leaves the very minor inconsistency that the return type always shows exactly what the source code contains whereas the parameter types will omit defaults that were unnecessarily included in the source code.
--- a/src/lib/converter/types.ts+++ b/src/lib/converter/types.ts@@ -824,23 +824,24 @@ const referenceConverter: TypeConverter<
convertType(context, (type as ts.StringMappingType).type),
];
} else {
- // Default type arguments are filled with a reference to the default- // type. As TS doesn't support specifying earlier defaults, we know- // that this will only filter out type arguments which aren't specified- // by the user.- let ignoredArgs: ts.Type[] | undefined;- if (isTypeReference(type)) {- ignoredArgs = type.target.typeParameters- ?.map((p) => p.getDefault())- .filter((x) => !!x);- }-
const args = type.aliasSymbol
? type.aliasTypeArguments
: (type as ts.TypeReference).typeArguments;
+ let idx;+ if (args && isTypeReference(type)) {+ idx = args.length - 1;+ while (+ idx >= 0 &&+ args?.at(idx) ===+ type.target.typeParameters?.at(idx)?.getDefault()+ ) {+ idx--;+ }+ }+
ref.typeArguments = args
- ?.filter((ref) => !ignoredArgs?.includes(ref))+ ?.slice(0, idx! + 1)
.map((ref) => convertType(context, ref));
}
return ref;
The text was updated successfully, but these errors were encountered:
Shoot, I completely forgot about intrinsic types which share identity with others... I'm pretty sure your proposed patch doesn't fix some cases as well. Will try to find the time to look at this again soon
The changes in #2820 have a couple of shortcomings. The new logic removes a type argument if it matches the default value of any type parameter. What we have to do is work from the last type argument backwards and check each one in turn for whether it matches the default. We need to include all arguments before the last nondefault argument even if they are defaults.
The following patch mostly fixes it, though it leaves the very minor inconsistency that the return type always shows exactly what the source code contains whereas the parameter types will omit defaults that were unnecessarily included in the source code.
The text was updated successfully, but these errors were encountered: