Skip to content

Commit d7443f0

Browse files
committed
Contextual typing by tuple rest elements
1 parent 3cc3b49 commit d7443f0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15531,8 +15531,19 @@ namespace ts {
1553115531

1553215532
function getTypeOfPropertyOfContextualType(type: Type, name: __String) {
1553315533
return mapType(type, t => {
15534-
const prop = t.flags & TypeFlags.StructuredType ? getPropertyOfType(t, name) : undefined;
15535-
return prop ? getTypeOfSymbol(prop) : undefined;
15534+
if (t.flags & TypeFlags.StructuredType) {
15535+
const prop = getPropertyOfType(t, name);
15536+
if (prop) {
15537+
return getTypeOfSymbol(prop);
15538+
}
15539+
if (isTupleType(t)) {
15540+
const restType = getRestTypeOfTupleType(t);
15541+
if (restType && isNumericLiteralName(name) && +name >= 0) {
15542+
return restType;
15543+
}
15544+
}
15545+
}
15546+
return undefined;
1553615547
}, /*noReductions*/ true);
1553715548
}
1553815549

0 commit comments

Comments
 (0)