Skip to content

Commit b748484

Browse files
authored
microsoft#40763 Fixed: Bad error message when forgetting a comma in an array of templ… (microsoft#40907)
* microsoft#40763 Bad error message when forgetting a comma in an array of template strings * Code review fixes
1 parent fb2f3d4 commit b748484

7 files changed

+58
-0
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27873,6 +27873,12 @@ namespace ts {
2787327873
}
2787427874

2787527875
if (!callSignatures.length) {
27876+
if (isArrayLiteralExpression(node.parent)) {
27877+
const diagnostic = createDiagnosticForNode(node.tag, Diagnostics.It_is_likely_that_you_are_missing_a_comma_to_separate_these_two_template_expressions_They_form_a_tagged_template_expression_which_cannot_be_invoked);
27878+
diagnostics.add(diagnostic);
27879+
return resolveErrorCall(node);
27880+
}
27881+
2787627882
invocationError(node.tag, apparentType, SignatureKind.Call);
2787727883
return resolveErrorCall(node);
2787827884
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,10 @@
30483048
"category": "Error",
30493049
"code": 2795
30503050
},
3051+
"It is likely that you are missing a comma to separate these two template expressions. They form a tagged template expression which cannot be invoked.": {
3052+
"category": "Error",
3053+
"code": 2796
3054+
},
30513055

30523056
"Import declaration '{0}' is using private name '{1}'.": {
30533057
"category": "Error",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests/cases/compiler/missingCommaInTemplateStringsArray.ts(2,5): error TS2796: It is likely that you are missing a comma to separate these two template expressions. They form a tagged template expression which cannot be invoked.
2+
3+
4+
==== tests/cases/compiler/missingCommaInTemplateStringsArray.ts (1 errors) ====
5+
var array = [
6+
`template string 1`
7+
~~~~~~~~~~~~~~~~~~~
8+
!!! error TS2796: It is likely that you are missing a comma to separate these two template expressions. They form a tagged template expression which cannot be invoked.
9+
`template string 2`
10+
];
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [missingCommaInTemplateStringsArray.ts]
2+
var array = [
3+
`template string 1`
4+
`template string 2`
5+
];
6+
7+
//// [missingCommaInTemplateStringsArray.js]
8+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
9+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
10+
return cooked;
11+
};
12+
var array = [
13+
"template string 1"(__makeTemplateObject(["template string 2"], ["template string 2"]))
14+
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/missingCommaInTemplateStringsArray.ts ===
2+
var array = [
3+
>array : Symbol(array, Decl(missingCommaInTemplateStringsArray.ts, 0, 3))
4+
5+
`template string 1`
6+
`template string 2`
7+
];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/missingCommaInTemplateStringsArray.ts ===
2+
var array = [
3+
>array : any[]
4+
>[ `template string 1` `template string 2` ] : any[]
5+
6+
`template string 1`
7+
>`template string 1` `template string 2` : any
8+
>`template string 1` : "template string 1"
9+
10+
`template string 2`
11+
>`template string 2` : "template string 2"
12+
13+
];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var array = [
2+
`template string 1`
3+
`template string 2`
4+
];

0 commit comments

Comments
 (0)