@@ -4949,6 +4949,12 @@ namespace ts {
4949
4949
return strictNullChecks && optional ? getOptionalType(type) : type;
4950
4950
}
4951
4951
4952
+ function isParameterOfContextuallyTypedFunction(node: Declaration) {
4953
+ return node.kind === SyntaxKind.Parameter &&
4954
+ (node.parent.kind === SyntaxKind.FunctionExpression || node.parent.kind === SyntaxKind.ArrowFunction) &&
4955
+ !!getContextualType(<Expression>node.parent);
4956
+ }
4957
+
4952
4958
// Return the inferred type for a variable, parameter, or property declaration
4953
4959
function getTypeForVariableLikeDeclaration(declaration: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement, includeOptionality: boolean): Type | undefined {
4954
4960
// A variable declared in a for..in statement is of type string, or of type keyof T when the
@@ -5032,11 +5038,9 @@ namespace ts {
5032
5038
}
5033
5039
}
5034
5040
5035
- const isParameterOfContextuallyTypedFunction = declaration.kind === SyntaxKind.Parameter && getContextualType(<Expression>declaration.parent);
5036
-
5037
5041
// Use the type of the initializer expression if one is present and the declaration is
5038
5042
// not a parameter of a contextually typed function
5039
- if (declaration.initializer && !isParameterOfContextuallyTypedFunction) {
5043
+ if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration) ) {
5040
5044
const type = checkDeclarationInitializer(declaration);
5041
5045
return addOptionality(type, isOptional);
5042
5046
}
@@ -5049,7 +5053,7 @@ namespace ts {
5049
5053
5050
5054
// If the declaration specifies a binding pattern and is not a parameter of a contextually
5051
5055
// typed function, use the type implied by the binding pattern
5052
- if (isBindingPattern(declaration.name) && !isParameterOfContextuallyTypedFunction) {
5056
+ if (isBindingPattern(declaration.name) && !isParameterOfContextuallyTypedFunction(declaration) ) {
5053
5057
return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ false, /*reportErrors*/ true);
5054
5058
}
5055
5059
@@ -5693,7 +5697,7 @@ namespace ts {
5693
5697
return errorType;
5694
5698
}
5695
5699
// Check if variable has initializer that circularly references the variable itself
5696
- if (noImplicitAny && (<HasInitializer>declaration).initializer) {
5700
+ if (noImplicitAny && (declaration.kind !== SyntaxKind.Parameter || ( <HasInitializer>declaration).initializer) ) {
5697
5701
error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer,
5698
5702
symbolToString(symbol));
5699
5703
}
0 commit comments