Skip to content

Commit

Permalink
Fix #2079
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Oct 23, 2022
1 parent c59b8bf commit c7c48f2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
16 changes: 12 additions & 4 deletions src/lib/converter/types.ts
Expand Up @@ -644,7 +644,7 @@ const queryConverter: TypeConverter<ts.TypeQueryNode> = {

const referenceConverter: TypeConverter<
ts.TypeReferenceNode,
ts.TypeReference
ts.TypeReference | ts.StringMappingType
> = {
kind: [ts.SyntaxKind.TypeReference],
convert(context, node) {
Expand Down Expand Up @@ -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;
},
};
Expand Down
5 changes: 5 additions & 0 deletions src/test/converter2/issues/gh2079.ts
@@ -0,0 +1,5 @@
export function capitalize<T extends string>(string: T) {
return (
string === "" ? "" : string[0].toUpperCase() + string.slice(1)
) as Capitalize<T>;
}
6 changes: 6 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -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<T>");
},
};

0 comments on commit c7c48f2

Please sign in to comment.