diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b249d7090dd78..259b24abcc91c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22480,18 +22480,26 @@ namespace ts { target = getActualTypeVariable(target); } if (target.flags & TypeFlags.TypeVariable) { - // If target is a type parameter, make an inference, unless the source type contains - // the anyFunctionType (the wildcard type that's used to avoid contextually typing functions). - // Because the anyFunctionType is internal, it should not be exposed to the user by adding - // it as an inference candidate. Hopefully, a better candidate will come along that does - // not contain anyFunctionType when we come back to this argument for its second round - // of inference. Also, we exclude inferences for silentNeverType (which is used as a wildcard - // when constructing types from type parameters that had no inference candidates). + // Skip inference if the source is "blocked", which is used by the language service to + // prevent inference on nodes currently being edited. if (isFromInferenceBlockedSource(source)) { return; } const inference = getInferenceInfoForType(target); if (inference) { + // If target is a type parameter, make an inference, unless the source type contains + // a "non-inferrable" type. Types with this flag set are markers used to prevent inference. + // + // For example: + // - anyFunctionType is a wildcard type that's used to avoid contextually typing functions; + // it's internal, so should not be exposed to the user by adding it as a candidate. + // - autoType/autoArrayType is a special "any" used in control; like anyFunctionType, it's internal + // and should not be observable. + // - silentNeverType is returned by getInferredType when instantiating a generic function for + // inference (and a type variable has no mapping). + // + // This flag is infectious; if we produce Box (where never is silentNeverType), Box is + // also non-inferrable. if (getObjectFlags(source) & ObjectFlags.NonInferrableType) { return; }