Skip to content

Commit 8ffc42f

Browse files
committed
Don't instantiate-in-context-of when inferring to type variable
1 parent 4fe2722 commit 8ffc42f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ namespace ts {
177177
const enum ContextFlags {
178178
None = 0,
179179
Signature = 1 << 0, // Obtaining contextual signature
180+
NoConstraints = 1 << 1, // Don't obtain type variable constraints
180181
}
181182

182183
const enum AccessFlags {
@@ -19193,7 +19194,7 @@ namespace ts {
1919319194
getContextualTypeForObjectLiteralMethod(node, contextFlags) :
1919419195
getContextualType(node, contextFlags);
1919519196
const instantiatedType = instantiateContextualType(contextualType, node, contextFlags);
19196-
if (instantiatedType) {
19197+
if (instantiatedType && !(contextFlags && contextFlags & ContextFlags.NoConstraints && instantiatedType.flags & TypeFlags.TypeVariable)) {
1919719198
const apparentType = mapType(instantiatedType, getApparentType, /*noReductions*/ true);
1919819199
if (apparentType.flags & TypeFlags.Union) {
1919919200
if (isObjectLiteralExpression(node)) {
@@ -25098,8 +25099,8 @@ namespace ts {
2509825099
const constructSignature = getSingleSignature(type, SignatureKind.Construct, /*allowMembers*/ true);
2509925100
const signature = callSignature || constructSignature;
2510025101
if (signature && signature.typeParameters) {
25101-
const contextualType = getApparentTypeOfContextualType(<Expression>node);
25102-
if (contextualType && !isMixinConstructorType(contextualType)) {
25102+
const contextualType = getApparentTypeOfContextualType(<Expression>node, ContextFlags.NoConstraints);
25103+
if (contextualType) {
2510325104
const contextualSignature = getSingleSignature(getNonNullableType(contextualType), callSignature ? SignatureKind.Call : SignatureKind.Construct, /*allowMembers*/ false);
2510425105
if (contextualSignature && !contextualSignature.typeParameters) {
2510525106
if (checkMode & CheckMode.SkipGenericFunctions) {

0 commit comments

Comments
 (0)