CFA for dependent parameters typed by generic constraints (#48411)

* Obtain apparent type in parameter destructuring check

* Add regression test
This commit is contained in:
Anders Hejlsberg
2022-03-30 16:33:01 -07:00
committed by GitHub
parent 3f483d87b4
commit fd601ddf20
5 changed files with 105 additions and 1 deletions

View File

@@ -25450,7 +25450,7 @@ namespace ts {
if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
const contextualSignature = getContextualSignature(func);
if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
const restType = getTypeOfSymbol(contextualSignature.parameters[0]);
const restType = getReducedApparentType(getTypeOfSymbol(contextualSignature.parameters[0]));
if (restType.flags & TypeFlags.Union && everyType(restType, isTupleType) && !isSymbolAssigned(symbol)) {
const narrowedType = getFlowTypeOfReference(func, restType, restType, /*flowContainer*/ undefined, location.flowNode);
const index = func.parameters.indexOf(declaration) - (getThisParameter(func) ? 1 : 0);