@@ -59,7 +59,20 @@ namespace ts {
59
59
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
60
60
getDiagnostics,
61
61
getGlobalDiagnostics,
62
- getTypeOfSymbolAtLocation,
62
+
63
+ // Get the narrowed type of symbol at given location instead of just getting
64
+ // the type of the symbol.
65
+ // eg.
66
+ // function foo(a: string | number) {
67
+ // if (typeof a === "string") {
68
+ // a/**/
69
+ // }
70
+ // }
71
+ // getTypeOfSymbol for a would return type of parameter symbol string | number
72
+ // Unless we provide location /**/, checker wouldn't know how to narrow the type
73
+ // By using getNarrowedTypeOfSymbol would return string since it would be able to narrow
74
+ // it by typeguard in the if true condition
75
+ getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol,
63
76
getDeclaredTypeOfSymbol,
64
77
getPropertiesOfType,
65
78
getPropertyOfType,
@@ -69,7 +82,7 @@ namespace ts {
69
82
getSymbolsInScope,
70
83
getSymbolAtLocation,
71
84
getShorthandAssignmentValueSymbol,
72
- getTypeAtLocation,
85
+ getTypeAtLocation: getTypeOfNode ,
73
86
typeToString,
74
87
getSymbolDisplayBuilder,
75
88
symbolToString,
@@ -4226,7 +4239,7 @@ namespace ts {
4226
4239
// Callers should first ensure this by calling isTypeNode
4227
4240
case SyntaxKind.Identifier:
4228
4241
case SyntaxKind.QualifiedName:
4229
- let symbol = getSymbolInfo (node);
4242
+ let symbol = getSymbolAtLocation (node);
4230
4243
return symbol && getDeclaredTypeOfSymbol(symbol);
4231
4244
default:
4232
4245
return unknownType;
@@ -5883,30 +5896,6 @@ namespace ts {
5883
5896
}
5884
5897
}
5885
5898
5886
- function getSymbolAtLocation(node: Node): Symbol {
5887
- return getSymbolInfo(node);
5888
- }
5889
-
5890
- function getTypeAtLocation(node: Node): Type {
5891
- return getTypeOfNode(node);
5892
- }
5893
-
5894
- function getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type {
5895
- // Get the narrowed type of symbol at given location instead of just getting
5896
- // the type of the symbol.
5897
- // eg.
5898
- // function foo(a: string | number) {
5899
- // if (typeof a === "string") {
5900
- // a/**/
5901
- // }
5902
- // }
5903
- // getTypeOfSymbol for a would return type of parameter symbol string | number
5904
- // Unless we provide location /**/, checker wouldn't know how to narrow the type
5905
- // By using getNarrowedTypeOfSymbol would return string since it would be able to narrow
5906
- // it by typeguard in the if true condition
5907
- return getNarrowedTypeOfSymbol(symbol, node);
5908
- }
5909
-
5910
5899
// Get the narrowed type of a given symbol at a given location
5911
5900
function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) {
5912
5901
let type = getTypeOfSymbol(symbol);
@@ -10136,7 +10125,7 @@ namespace ts {
10136
10125
}
10137
10126
else {
10138
10127
checkTypeAssignableTo(typePredicate.type,
10139
- getTypeAtLocation (node.parameters[typePredicate.parameterIndex]),
10128
+ getTypeOfNode (node.parameters[typePredicate.parameterIndex]),
10140
10129
typePredicateNode.type);
10141
10130
}
10142
10131
}
@@ -13758,7 +13747,7 @@ namespace ts {
13758
13747
return undefined;
13759
13748
}
13760
13749
13761
- function getSymbolInfo (node: Node) {
13750
+ function getSymbolAtLocation (node: Node) {
13762
13751
if (isInsideWithStatementBody(node)) {
13763
13752
// We cannot answer semantic questions within a with block, do not proceed any further
13764
13753
return undefined;
@@ -13778,7 +13767,7 @@ namespace ts {
13778
13767
else if (node.parent.kind === SyntaxKind.BindingElement &&
13779
13768
node.parent.parent.kind === SyntaxKind.ObjectBindingPattern &&
13780
13769
node === (<BindingElement>node.parent).propertyName) {
13781
- let typeOfPattern = getTypeAtLocation (node.parent.parent);
13770
+ let typeOfPattern = getTypeOfNode (node.parent.parent);
13782
13771
let propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, (<Identifier>node).text);
13783
13772
13784
13773
if (propertyDeclaration) {
@@ -13861,24 +13850,24 @@ namespace ts {
13861
13850
}
13862
13851
13863
13852
if (isTypeDeclaration(node)) {
13864
- // In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration
13853
+ // In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
13865
13854
let symbol = getSymbolOfNode(node);
13866
13855
return getDeclaredTypeOfSymbol(symbol);
13867
13856
}
13868
13857
13869
13858
if (isTypeDeclarationName(node)) {
13870
- let symbol = getSymbolInfo (node);
13859
+ let symbol = getSymbolAtLocation (node);
13871
13860
return symbol && getDeclaredTypeOfSymbol(symbol);
13872
13861
}
13873
13862
13874
13863
if (isDeclaration(node)) {
13875
- // In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration
13864
+ // In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
13876
13865
let symbol = getSymbolOfNode(node);
13877
13866
return getTypeOfSymbol(symbol);
13878
13867
}
13879
13868
13880
13869
if (isDeclarationName(node)) {
13881
- let symbol = getSymbolInfo (node);
13870
+ let symbol = getSymbolAtLocation (node);
13882
13871
return symbol && getTypeOfSymbol(symbol);
13883
13872
}
13884
13873
@@ -13887,7 +13876,7 @@ namespace ts {
13887
13876
}
13888
13877
13889
13878
if (isInRightSideOfImportOrExportAssignment(<Identifier>node)) {
13890
- let symbol = getSymbolInfo (node);
13879
+ let symbol = getSymbolAtLocation (node);
13891
13880
let declaredType = symbol && getDeclaredTypeOfSymbol(symbol);
13892
13881
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
13893
13882
}
0 commit comments