Skip to content

Commit

Permalink
fix(23716): show generic type in tagged template expression
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed May 26, 2020
1 parent ff36bf0 commit 6e98431
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/symbolDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ namespace ts.SymbolDisplay {
}

// try get the call/construct signature from the type if it matches
let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement | undefined;
let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement | TaggedTemplateExpression | undefined;
if (isCallOrNewExpression(location)) {
callExpressionLike = location;
}
else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) {
callExpressionLike = <CallExpression | NewExpression>location.parent;
}
else if (location.parent && isJsxOpeningLikeElement(location.parent) && isFunctionLike(symbol.valueDeclaration)) {
else if (location.parent && (isJsxOpeningLikeElement(location.parent) || isTaggedTemplateExpression(location.parent)) && isFunctionLike(symbol.valueDeclaration)) {
callExpressionLike = location.parent;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// <reference path='fourslash.ts'/>

////interface T1 {}
////class T2 {}
////type T3 = "a" | "b";
////
////declare function foo<T>(strings: TemplateStringsArray, ...values: T[]): void;
////
/////*1*/foo<number>``;
/////*2*/foo<string | number>``;
/////*3*/foo<{ a: number }>``;
/////*4*/foo<T1>``;
/////*5*/foo<T2>``;
/////*6*/foo<T3>``;
/////*7*/foo``;

verify.quickInfoAt("1", "function foo<number>(strings: TemplateStringsArray, ...values: number[]): void");
verify.quickInfoAt("2", "function foo<string | number>(strings: TemplateStringsArray, ...values: (string | number)[]): void");
verify.quickInfoAt("3",
`function foo<{
a: number;
}>(strings: TemplateStringsArray, ...values: {
a: number;
}[]): void`);
verify.quickInfoAt("4", "function foo<T1>(strings: TemplateStringsArray, ...values: T1[]): void");
verify.quickInfoAt("5", "function foo<T2>(strings: TemplateStringsArray, ...values: T2[]): void");
verify.quickInfoAt("6", "function foo<T3>(strings: TemplateStringsArray, ...values: T3[]): void");
verify.quickInfoAt("7", "function foo<unknown>(strings: TemplateStringsArray, ...values: unknown[]): void");

0 comments on commit 6e98431

Please sign in to comment.