Skip to content

Commit 58ff76a

Browse files
committed
Properly instantiate contextual type for object literal methods
1 parent 3d09010 commit 58ff76a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19099,10 +19099,13 @@ namespace ts {
1909919099

1910019100
// Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
1910119101
// be "pushed" onto a node using the contextualType property.
19102-
function getApparentTypeOfContextualType(node: Expression, contextFlags?: ContextFlags): Type | undefined {
19103-
const contextualType = instantiateContextualType(getContextualType(node, contextFlags), node, contextFlags);
19104-
if (contextualType) {
19105-
const apparentType = mapType(contextualType, getApparentType, /*noReductions*/ true);
19102+
function getApparentTypeOfContextualType(node: Expression | MethodDeclaration, contextFlags?: ContextFlags): Type | undefined {
19103+
const contextualType = isObjectLiteralMethod(node) ?
19104+
getContextualTypeForObjectLiteralMethod(node, contextFlags) :
19105+
getContextualType(node, contextFlags);
19106+
const instantiatedType = instantiateContextualType(contextualType, node, contextFlags);
19107+
if (instantiatedType) {
19108+
const apparentType = mapType(instantiatedType, getApparentType, /*noReductions*/ true);
1910619109
if (apparentType.flags & TypeFlags.Union) {
1910719110
if (isObjectLiteralExpression(node)) {
1910819111
return discriminateContextualTypeByObjectMembers(node, apparentType as UnionType);
@@ -19426,9 +19429,7 @@ namespace ts {
1942619429
if (typeTagSignature) {
1942719430
return typeTagSignature;
1942819431
}
19429-
const type = isObjectLiteralMethod(node) ?
19430-
getContextualTypeForObjectLiteralMethod(node, ContextFlags.Signature) :
19431-
getApparentTypeOfContextualType(node, ContextFlags.Signature);
19432+
const type = getApparentTypeOfContextualType(node, ContextFlags.Signature);
1943219433
if (!type) {
1943319434
return undefined;
1943419435
}

0 commit comments

Comments
 (0)