@@ -4949,6 +4949,12 @@ namespace ts {
49494949 return strictNullChecks && optional ? getOptionalType(type) : type;
49504950 }
49514951
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+
49524958 // Return the inferred type for a variable, parameter, or property declaration
49534959 function getTypeForVariableLikeDeclaration(declaration: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement, includeOptionality: boolean): Type | undefined {
49544960 // 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 {
50325038 }
50335039 }
50345040
5035- const isParameterOfContextuallyTypedFunction = declaration.kind === SyntaxKind.Parameter && getContextualType(<Expression>declaration.parent);
5036-
50375041 // Use the type of the initializer expression if one is present and the declaration is
50385042 // not a parameter of a contextually typed function
5039- if (declaration.initializer && !isParameterOfContextuallyTypedFunction) {
5043+ if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration) ) {
50405044 const type = checkDeclarationInitializer(declaration);
50415045 return addOptionality(type, isOptional);
50425046 }
@@ -5049,7 +5053,7 @@ namespace ts {
50495053
50505054 // If the declaration specifies a binding pattern and is not a parameter of a contextually
50515055 // typed function, use the type implied by the binding pattern
5052- if (isBindingPattern(declaration.name) && !isParameterOfContextuallyTypedFunction) {
5056+ if (isBindingPattern(declaration.name) && !isParameterOfContextuallyTypedFunction(declaration) ) {
50535057 return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ false, /*reportErrors*/ true);
50545058 }
50555059
@@ -5693,7 +5697,7 @@ namespace ts {
56935697 return errorType;
56945698 }
56955699 // 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) ) {
56975701 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,
56985702 symbolToString(symbol));
56995703 }
0 commit comments