Stop looking at binding patterns for type argument inference (#45719)

* Ignore empty binding patterns for contextual typing

* Stop looking at binding patterns for type argument inference entirely
This commit is contained in:
Andrew Branch
2021-09-07 17:14:06 -07:00
committed by GitHub
parent bac841ef18
commit be618b1446
4 changed files with 18 additions and 26 deletions

View File

@@ -25314,7 +25314,8 @@ namespace ts {
if (result) {
return result;
}
if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable
if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name)) {
// This is less a contextual type and more an implied shape - in some cases, this may be undesirable
return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
}
}
@@ -28613,7 +28614,7 @@ namespace ts {
// 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the
// return type of 'wrap'.
if (node.kind !== SyntaxKind.Decorator) {
const contextualType = getContextualType(node, every(signature.typeParameters, p => !!getDefaultFromTypeParameter(p)) ? ContextFlags.SkipBindingPatterns : ContextFlags.None);
const contextualType = getContextualType(node, ContextFlags.SkipBindingPatterns);
if (contextualType) {
// We clone the inference context to avoid disturbing a resolution in progress for an
// outer call expression. Effectively we just want a snapshot of whatever has been