@@ -17191,30 +17191,38 @@ namespace ts {
17191
17191
getEffectiveTypeAnnotationNode(declaration as VariableDeclaration | ParameterDeclaration | PropertyDeclaration | PropertySignature));
17192
17192
}
17193
17193
17194
- function getExplicitTypeOfSymbol(symbol: Symbol) {
17195
- return symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.ValueModule) ||
17196
- symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property) && isDeclarationWithExplicitTypeAnnotation(symbol.valueDeclaration) ?
17197
- getTypeOfSymbol(symbol) : undefined;
17194
+ function getExplicitTypeOfSymbol(symbol: Symbol, diagnostic?: Diagnostic) {
17195
+ if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.ValueModule)) {
17196
+ return getTypeOfSymbol(symbol);
17197
+ }
17198
+ if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) {
17199
+ if (isDeclarationWithExplicitTypeAnnotation(symbol.valueDeclaration)) {
17200
+ return getTypeOfSymbol(symbol);
17201
+ }
17202
+ if (diagnostic && symbol.valueDeclaration) {
17203
+ addRelatedInfo(diagnostic, createDiagnosticForNode(symbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(symbol)));
17204
+ }
17205
+ }
17198
17206
}
17199
17207
17200
17208
// We require the dotted function name in an assertion expression to be comprised of identifiers
17201
17209
// that reference function, method, class or value module symbols; or variable, property or
17202
17210
// parameter symbols with declarations that have explicit type annotations. Such references are
17203
17211
// resolvable with no possibility of triggering circularities in control flow analysis.
17204
- function getTypeOfDottedName(node: Expression): Type | undefined {
17212
+ function getTypeOfDottedName(node: Expression, diagnostic: Diagnostic | undefined ): Type | undefined {
17205
17213
if (!(node.flags & NodeFlags.InWithStatement)) {
17206
17214
switch (node.kind) {
17207
17215
case SyntaxKind.Identifier:
17208
17216
const symbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>node));
17209
- return getExplicitTypeOfSymbol(symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol);
17217
+ return getExplicitTypeOfSymbol(symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol, diagnostic );
17210
17218
case SyntaxKind.ThisKeyword:
17211
17219
return getExplicitThisType(node);
17212
17220
case SyntaxKind.PropertyAccessExpression:
17213
- const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression);
17221
+ const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression, diagnostic );
17214
17222
const prop = type && getPropertyOfType(type, (<PropertyAccessExpression>node).name.escapedText);
17215
- return prop && getExplicitTypeOfSymbol(prop);
17223
+ return prop && getExplicitTypeOfSymbol(prop, diagnostic );
17216
17224
case SyntaxKind.ParenthesizedExpression:
17217
- return getTypeOfDottedName((<ParenthesizedExpression>node).expression);
17225
+ return getTypeOfDottedName((<ParenthesizedExpression>node).expression, diagnostic );
17218
17226
}
17219
17227
}
17220
17228
}
@@ -17227,7 +17235,7 @@ namespace ts {
17227
17235
// expressions are potential type predicate function calls. In order to avoid triggering
17228
17236
// circularities in control flow analysis, we use getTypeOfDottedName when resolving the call
17229
17237
// target expression of an assertion.
17230
- const funcType = node.parent.kind === SyntaxKind.ExpressionStatement ? getTypeOfDottedName(node.expression) :
17238
+ const funcType = node.parent.kind === SyntaxKind.ExpressionStatement ? getTypeOfDottedName(node.expression, /*diagnostic*/ undefined ) :
17231
17239
node.expression.kind !== SyntaxKind.SuperKeyword ? checkNonNullExpression(node.expression) :
17232
17240
undefined;
17233
17241
const signatures = getSignaturesOfType(funcType && getApparentType(funcType) || unknownType, SignatureKind.Call);
@@ -23417,12 +23425,13 @@ namespace ts {
23417
23425
return getESSymbolLikeTypeForNode(walkUpParenthesizedExpressions(node.parent));
23418
23426
}
23419
23427
if (node.kind === SyntaxKind.CallExpression && node.parent.kind === SyntaxKind.ExpressionStatement &&
23420
- returnType.flags & ( TypeFlags.Void | TypeFlags.Never) && hasTypePredicateOrNeverReturnType (signature)) {
23428
+ returnType.flags & TypeFlags.Void && getTypePredicateOfSignature (signature)) {
23421
23429
if (!isDottedName(node.expression)) {
23422
- error(node.expression, Diagnostics.Control_flow_effects_of_calls_to_assertion_and_never_returning_functions_are_reflected_only_when_the_function_expression_is_an_identifier_or_qualified_name );
23430
+ error(node.expression, Diagnostics.Assertions_require_the_call_target_to_be_an_identifier_or_qualified_name );
23423
23431
}
23424
23432
else if (!getEffectsSignature(node)) {
23425
- error(node.expression, Diagnostics.Control_flow_effects_of_calls_to_assertion_and_never_returning_functions_are_reflected_only_when_every_variable_or_property_referenced_in_the_function_expression_is_declared_with_an_explicit_type_annotation);
23433
+ const diagnostic = error(node.expression, Diagnostics.Assertions_require_every_name_in_the_call_target_to_be_declared_with_an_explicit_type_annotation);
23434
+ getTypeOfDottedName(node.expression, diagnostic);
23426
23435
}
23427
23436
}
23428
23437
let jsAssignmentType: Type | undefined;
0 commit comments