diff --git a/CHANGELOG.md b/CHANGELOG.md index 37eb2b95f..201e149b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +### Bug Fixes + +- Fixed conversion of intrinsic string mapping types when converting without a type node, #2079. + ## v0.23.17 (2022-10-18) ### Features diff --git a/src/lib/converter/types.ts b/src/lib/converter/types.ts index cbd02af1c..c61bfe062 100644 --- a/src/lib/converter/types.ts +++ b/src/lib/converter/types.ts @@ -644,7 +644,7 @@ const queryConverter: TypeConverter = { const referenceConverter: TypeConverter< ts.TypeReferenceNode, - ts.TypeReference + ts.TypeReference | ts.StringMappingType > = { kind: [ts.SyntaxKind.TypeReference], convert(context, node) { @@ -688,9 +688,17 @@ const referenceConverter: TypeConverter< context.resolveAliasedSymbol(symbol), context ); - ref.typeArguments = ( - type.aliasSymbol ? type.aliasTypeArguments : type.typeArguments - )?.map((ref) => convertType(context, ref)); + if (type.flags & ts.TypeFlags.StringMapping) { + ref.typeArguments = [ + convertType(context, (type as ts.StringMappingType).type), + ]; + } else { + ref.typeArguments = ( + type.aliasSymbol + ? type.aliasTypeArguments + : (type as ts.TypeReference).typeArguments + )?.map((ref) => convertType(context, ref)); + } return ref; }, }; diff --git a/src/test/converter2/issues/gh2079.ts b/src/test/converter2/issues/gh2079.ts new file mode 100644 index 000000000..80150316c --- /dev/null +++ b/src/test/converter2/issues/gh2079.ts @@ -0,0 +1,5 @@ +export function capitalize(string: T) { + return ( + string === "" ? "" : string[0].toUpperCase() + string.slice(1) + ) as Capitalize; +} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 165e88763..67fc742df 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -803,4 +803,10 @@ export const issueTests: { gh2064(project) { query(project, "PrivateCtorDecl.x"); }, + + gh2079(project) { + const cap = query(project, "capitalize"); + const sig = cap.signatures![0]; + equal(sig.type?.toString(), "Capitalize"); + }, };