Properly instantiate contextual type for object literal methods

This commit is contained in:
Anders Hejlsberg
2019-07-28 09:01:11 -07:00
parent 3d09010dc8
commit 58ff76abf6

View File

@@ -19099,10 +19099,13 @@ namespace ts {
// Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
// be "pushed" onto a node using the contextualType property.
function getApparentTypeOfContextualType(node: Expression, contextFlags?: ContextFlags): Type | undefined {
const contextualType = instantiateContextualType(getContextualType(node, contextFlags), node, contextFlags);
if (contextualType) {
const apparentType = mapType(contextualType, getApparentType, /*noReductions*/ true);
function getApparentTypeOfContextualType(node: Expression | MethodDeclaration, contextFlags?: ContextFlags): Type | undefined {
const contextualType = isObjectLiteralMethod(node) ?
getContextualTypeForObjectLiteralMethod(node, contextFlags) :
getContextualType(node, contextFlags);
const instantiatedType = instantiateContextualType(contextualType, node, contextFlags);
if (instantiatedType) {
const apparentType = mapType(instantiatedType, getApparentType, /*noReductions*/ true);
if (apparentType.flags & TypeFlags.Union) {
if (isObjectLiteralExpression(node)) {
return discriminateContextualTypeByObjectMembers(node, apparentType as UnionType);
@@ -19426,9 +19429,7 @@ namespace ts {
if (typeTagSignature) {
return typeTagSignature;
}
const type = isObjectLiteralMethod(node) ?
getContextualTypeForObjectLiteralMethod(node, ContextFlags.Signature) :
getApparentTypeOfContextualType(node, ContextFlags.Signature);
const type = getApparentTypeOfContextualType(node, ContextFlags.Signature);
if (!type) {
return undefined;
}