@@ -791,6 +791,7 @@ namespace ts {
791
791
const wildcardType = createIntrinsicType(TypeFlags.Any, "any");
792
792
const errorType = createIntrinsicType(TypeFlags.Any, "error");
793
793
const unresolvedType = createIntrinsicType(TypeFlags.Any, "unresolved");
794
+ const nonInferrableAnyType = createIntrinsicType(TypeFlags.Any, "any", ObjectFlags.ContainsWideningType);
794
795
const intrinsicMarkerType = createIntrinsicType(TypeFlags.Any, "intrinsic");
795
796
const unknownType = createIntrinsicType(TypeFlags.Unknown, "unknown");
796
797
const nonNullUnknownType = createIntrinsicType(TypeFlags.Unknown, "unknown");
@@ -9560,7 +9561,11 @@ namespace ts {
9560
9561
if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) {
9561
9562
reportImplicitAny(element, anyType);
9562
9563
}
9563
- return anyType;
9564
+ // When we're including the pattern in the type (an indication we're obtaining a contextual type), we
9565
+ // use a non-inferrable any type. Inference will never directly infer this type, but it is possible
9566
+ // to infer a type that contains it, e.g. for a binding pattern like [foo] or { foo }. In such cases,
9567
+ // widening of the binding pattern type substitutes a regular any for the non-inferrable any.
9568
+ return includePatternInType ? nonInferrableAnyType : anyType;
9564
9569
}
9565
9570
9566
9571
// Return the type implied by an object binding pattern
@@ -22631,7 +22636,10 @@ namespace ts {
22631
22636
//
22632
22637
// This flag is infectious; if we produce Box<never> (where never is silentNeverType), Box<never> is
22633
22638
// also non-inferrable.
22634
- if (getObjectFlags(source) & ObjectFlags.NonInferrableType) {
22639
+ //
22640
+ // As a special case, also ignore nonInferrableAnyType, which is a special form of the any type
22641
+ // used as a stand-in for binding elements when they are being inferred.
22642
+ if (getObjectFlags(source) & ObjectFlags.NonInferrableType || source === nonInferrableAnyType) {
22635
22643
return;
22636
22644
}
22637
22645
if (!inference.isFixed) {
0 commit comments