Skip to content

Commit 5486b0d

Browse files
author
Andy Hanson
committed
Treat NoSubstitutionTemplateLiteral same as a StringLiteral
1 parent e73d58e commit 5486b0d

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17738,15 +17738,14 @@ namespace ts {
1773817738
return getBestChoiceType(type1, type2);
1773917739
}
1774017740

17741-
function checkLiteralExpression(node: Expression): Type {
17742-
if (node.kind === SyntaxKind.NumericLiteral) {
17743-
checkGrammarNumericLiteral(<NumericLiteral>node);
17744-
}
17741+
function checkLiteralExpression(node: LiteralExpression | Token<SyntaxKind.TrueKeyword | SyntaxKind.FalseKeyword>): Type {
1774517742
switch (node.kind) {
17743+
case SyntaxKind.NoSubstitutionTemplateLiteral:
1774617744
case SyntaxKind.StringLiteral:
17747-
return getFreshTypeOfLiteralType(getLiteralType((<LiteralExpression>node).text));
17745+
return getFreshTypeOfLiteralType(getLiteralType(node.text));
1774817746
case SyntaxKind.NumericLiteral:
17749-
return getFreshTypeOfLiteralType(getLiteralType(+(<LiteralExpression>node).text));
17747+
checkGrammarNumericLiteral(<NumericLiteral>node);
17748+
return getFreshTypeOfLiteralType(getLiteralType(+node.text));
1775017749
case SyntaxKind.TrueKeyword:
1775117750
return trueType;
1775217751
case SyntaxKind.FalseKeyword:
@@ -17964,15 +17963,14 @@ namespace ts {
1796417963
return checkSuperExpression(node);
1796517964
case SyntaxKind.NullKeyword:
1796617965
return nullWideningType;
17966+
case SyntaxKind.NoSubstitutionTemplateLiteral:
1796717967
case SyntaxKind.StringLiteral:
1796817968
case SyntaxKind.NumericLiteral:
1796917969
case SyntaxKind.TrueKeyword:
1797017970
case SyntaxKind.FalseKeyword:
17971-
return checkLiteralExpression(node);
17971+
return checkLiteralExpression(node as LiteralExpression);
1797217972
case SyntaxKind.TemplateExpression:
1797317973
return checkTemplateExpression(<TemplateExpression>node);
17974-
case SyntaxKind.NoSubstitutionTemplateLiteral:
17975-
return stringType;
1797617974
case SyntaxKind.RegularExpressionLiteral:
1797717975
return globalRegExpType;
1797817976
case SyntaxKind.ArrayLiteralExpression:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [stringLiteralNoSubstitutionTemplate.ts]
2+
const x: "foo" = `foo`;
3+
4+
5+
//// [stringLiteralNoSubstitutionTemplate.js]
6+
var x = "foo";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/types/stringLiteral/stringLiteralNoSubstitutionTemplate.ts ===
2+
const x: "foo" = `foo`;
3+
>x : Symbol(x, Decl(stringLiteralNoSubstitutionTemplate.ts, 0, 5))
4+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/types/stringLiteral/stringLiteralNoSubstitutionTemplate.ts ===
2+
const x: "foo" = `foo`;
3+
>x : "foo"
4+
>`foo` : "foo"
5+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const x: "foo" = `foo`;

0 commit comments

Comments
 (0)