Skip to content

Commit 9b0231d

Browse files
committed
Minor change to getStringLiteralType
1 parent f5b8619 commit 9b0231d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4531,8 +4531,7 @@ namespace ts {
45314531
return links.resolvedType;
45324532
}
45334533

4534-
function getStringLiteralType(node: StringLiteral | StringLiteralTypeNode): StringLiteralType {
4535-
const text = node.text;
4534+
function getStringLiteralType(text: string): StringLiteralType {
45364535
if (hasProperty(stringLiteralTypes, text)) {
45374536
return stringLiteralTypes[text];
45384537
}
@@ -4545,7 +4544,7 @@ namespace ts {
45454544
function getTypeFromStringLiteral(node: StringLiteral | StringLiteralTypeNode): Type {
45464545
const links = getNodeLinks(node);
45474546
if (!links.resolvedType) {
4548-
links.resolvedType = getStringLiteralType(node);
4547+
links.resolvedType = getStringLiteralType(node.text);
45494548
}
45504549
return links.resolvedType;
45514550
}
@@ -8747,7 +8746,7 @@ namespace ts {
87478746
// for the argument. In that case, we should check the argument.
87488747
if (argType === undefined) {
87498748
argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors
8750-
? getStringLiteralType(<StringLiteral>arg)
8749+
? getStringLiteralType((<StringLiteral>arg).text)
87518750
: checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
87528751
}
87538752

@@ -8942,7 +8941,7 @@ namespace ts {
89428941
case SyntaxKind.Identifier:
89438942
case SyntaxKind.NumericLiteral:
89448943
case SyntaxKind.StringLiteral:
8945-
return getStringLiteralType(<StringLiteral>element.name);
8944+
return getStringLiteralType((<Identifier | LiteralExpression>element.name).text);
89468945

89478946
case SyntaxKind.ComputedPropertyName:
89488947
const nameType = checkComputedPropertyName(<ComputedPropertyName>element.name);
@@ -10564,7 +10563,8 @@ namespace ts {
1056410563
function checkStringLiteralExpression(node: StringLiteral): Type {
1056510564
const contextualType = getContextualType(node);
1056610565
if (contextualType && contextualTypeIsStringLiteralType(contextualType)) {
10567-
return getStringLiteralType(node);
10566+
// TODO (drosen): Consider using getTypeFromStringLiteral instead
10567+
return getStringLiteralType(node.text);
1056810568
}
1056910569

1057010570
return stringType;

0 commit comments

Comments
 (0)