@@ -785,11 +785,10 @@ namespace ts {
785
785
const errorTypes = new Map<string, Type>();
786
786
787
787
const anyType = createIntrinsicType(TypeFlags.Any, "any");
788
- const autoType = createIntrinsicType(TypeFlags.Any, "any");
788
+ const autoType = createIntrinsicType(TypeFlags.Any, "any", ObjectFlags.NonInferrableType );
789
789
const wildcardType = createIntrinsicType(TypeFlags.Any, "any");
790
790
const errorType = createIntrinsicType(TypeFlags.Any, "error");
791
791
const unresolvedType = createIntrinsicType(TypeFlags.Any, "unresolved");
792
- const nonInferrableAnyType = createIntrinsicType(TypeFlags.Any, "any", ObjectFlags.ContainsWideningType);
793
792
const intrinsicMarkerType = createIntrinsicType(TypeFlags.Any, "intrinsic");
794
793
const unknownType = createIntrinsicType(TypeFlags.Unknown, "unknown");
795
794
const nonNullUnknownType = createIntrinsicType(TypeFlags.Unknown, "unknown");
@@ -818,8 +817,7 @@ namespace ts {
818
817
const esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol");
819
818
const voidType = createIntrinsicType(TypeFlags.Void, "void");
820
819
const neverType = createIntrinsicType(TypeFlags.Never, "never");
821
- const silentNeverType = createIntrinsicType(TypeFlags.Never, "never");
822
- const nonInferrableType = createIntrinsicType(TypeFlags.Never, "never", ObjectFlags.NonInferrableType);
820
+ const silentNeverType = createIntrinsicType(TypeFlags.Never, "never", ObjectFlags.NonInferrableType);
823
821
const implicitNeverType = createIntrinsicType(TypeFlags.Never, "never");
824
822
const unreachableNeverType = createIntrinsicType(TypeFlags.Never, "never");
825
823
const nonPrimitiveType = createIntrinsicType(TypeFlags.NonPrimitive, "object");
@@ -9456,11 +9454,7 @@ namespace ts {
9456
9454
if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) {
9457
9455
reportImplicitAny(element, anyType);
9458
9456
}
9459
- // When we're including the pattern in the type (an indication we're obtaining a contextual type), we
9460
- // use the non-inferrable any type. Inference will never directly infer this type, but it is possible
9461
- // to infer a type that contains it, e.g. for a binding pattern like [foo] or { foo }. In such cases,
9462
- // widening of the binding pattern type substitutes a regular any for the non-inferrable any.
9463
- return includePatternInType ? nonInferrableAnyType : anyType;
9457
+ return anyType;
9464
9458
}
9465
9459
9466
9460
// Return the type implied by an object binding pattern
@@ -13499,12 +13493,12 @@ namespace ts {
13499
13493
13500
13494
// This function is used to propagate certain flags when creating new object type references and union types.
13501
13495
// It is only necessary to do so if a constituent type might be the undefined type, the null type, the type
13502
- // of an object literal or the anyFunctionType . This is because there are operations in the type checker
13496
+ // of an object literal or a non-inferrable type . This is because there are operations in the type checker
13503
13497
// that care about the presence of such types at arbitrary depth in a containing type.
13504
- function getPropagatingFlagsOfTypes(types: readonly Type[], excludeKinds: TypeFlags): ObjectFlags {
13498
+ function getPropagatingFlagsOfTypes(types: readonly Type[], excludeKinds? : TypeFlags): ObjectFlags {
13505
13499
let result: ObjectFlags = 0;
13506
13500
for (const type of types) {
13507
- if (!(type.flags & excludeKinds)) {
13501
+ if (excludeKinds === undefined || !(type.flags & excludeKinds)) {
13508
13502
result |= getObjectFlags(type);
13509
13503
}
13510
13504
}
@@ -13517,7 +13511,7 @@ namespace ts {
13517
13511
if (!type) {
13518
13512
type = createObjectType(ObjectFlags.Reference, target.symbol) as TypeReference;
13519
13513
target.instantiations.set(id, type);
13520
- type.objectFlags |= typeArguments ? getPropagatingFlagsOfTypes(typeArguments, /*excludeKinds*/ 0 ) : 0;
13514
+ type.objectFlags |= typeArguments ? getPropagatingFlagsOfTypes(typeArguments) : 0;
13521
13515
type.target = target;
13522
13516
type.resolvedTypeArguments = typeArguments;
13523
13517
}
@@ -17196,6 +17190,7 @@ namespace ts {
17196
17190
result.mapper = mapper;
17197
17191
result.aliasSymbol = aliasSymbol || type.aliasSymbol;
17198
17192
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
17193
+ result.objectFlags |= result.aliasTypeArguments ? getPropagatingFlagsOfTypes(result.aliasTypeArguments) : 0;
17199
17194
return result;
17200
17195
}
17201
17196
@@ -22422,10 +22417,13 @@ namespace ts {
22422
22417
propagationType = savePropagationType;
22423
22418
return;
22424
22419
}
22425
- if (source.aliasSymbol && source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) {
22426
- // Source and target are types originating in the same generic type alias declaration.
22427
- // Simply infer from source type arguments to target type arguments.
22428
- inferFromTypeArguments(source.aliasTypeArguments, target.aliasTypeArguments!, getAliasVariances(source.aliasSymbol));
22420
+ if (source.aliasSymbol && source.aliasSymbol === target.aliasSymbol) {
22421
+ if (source.aliasTypeArguments) {
22422
+ // Source and target are types originating in the same generic type alias declaration.
22423
+ // Simply infer from source type arguments to target type arguments.
22424
+ inferFromTypeArguments(source.aliasTypeArguments, target.aliasTypeArguments!, getAliasVariances(source.aliasSymbol));
22425
+ }
22426
+ // And if there weren't any type arguments, there's no reason to run inference as the types must be the same.
22429
22427
return;
22430
22428
}
22431
22429
if (source === target && source.flags & TypeFlags.UnionOrIntersection) {
@@ -22481,18 +22479,26 @@ namespace ts {
22481
22479
target = getActualTypeVariable(target);
22482
22480
}
22483
22481
if (target.flags & TypeFlags.TypeVariable) {
22484
- // If target is a type parameter, make an inference, unless the source type contains
22485
- // the anyFunctionType (the wildcard type that's used to avoid contextually typing functions).
22486
- // Because the anyFunctionType is internal, it should not be exposed to the user by adding
22487
- // it as an inference candidate. Hopefully, a better candidate will come along that does
22488
- // not contain anyFunctionType when we come back to this argument for its second round
22489
- // of inference. Also, we exclude inferences for silentNeverType (which is used as a wildcard
22490
- // when constructing types from type parameters that had no inference candidates).
22491
- if (source === nonInferrableAnyType || source === silentNeverType || (priority & InferencePriority.ReturnType && (source === autoType || source === autoArrayType)) || isFromInferenceBlockedSource(source)) {
22482
+ // Skip inference if the source is "blocked", which is used by the language service to
22483
+ // prevent inference on nodes currently being edited.
22484
+ if (isFromInferenceBlockedSource(source)) {
22492
22485
return;
22493
22486
}
22494
22487
const inference = getInferenceInfoForType(target);
22495
22488
if (inference) {
22489
+ // If target is a type parameter, make an inference, unless the source type contains
22490
+ // a "non-inferrable" type. Types with this flag set are markers used to prevent inference.
22491
+ //
22492
+ // For example:
22493
+ // - anyFunctionType is a wildcard type that's used to avoid contextually typing functions;
22494
+ // it's internal, so should not be exposed to the user by adding it as a candidate.
22495
+ // - autoType (and autoArrayType) is a special "any" used in control flow; like anyFunctionType,
22496
+ // it's internal and should not be observable.
22497
+ // - silentNeverType is returned by getInferredType when instantiating a generic function for
22498
+ // inference (and a type variable has no mapping).
22499
+ //
22500
+ // This flag is infectious; if we produce Box<never> (where never is silentNeverType), Box<never> is
22501
+ // also non-inferrable.
22496
22502
if (getObjectFlags(source) & ObjectFlags.NonInferrableType) {
22497
22503
return;
22498
22504
}
@@ -23043,21 +23049,18 @@ namespace ts {
23043
23049
const sourceLen = sourceSignatures.length;
23044
23050
const targetLen = targetSignatures.length;
23045
23051
const len = sourceLen < targetLen ? sourceLen : targetLen;
23046
- const skipParameters = !!(getObjectFlags(source) & ObjectFlags.NonInferrableType);
23047
23052
for (let i = 0; i < len; i++) {
23048
- inferFromSignature(getBaseSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]), skipParameters );
23053
+ inferFromSignature(getBaseSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]));
23049
23054
}
23050
23055
}
23051
23056
23052
- function inferFromSignature(source: Signature, target: Signature, skipParameters: boolean) {
23053
- if (!skipParameters) {
23054
- const saveBivariant = bivariant;
23055
- const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown;
23056
- // Once we descend into a bivariant signature we remain bivariant for all nested inferences
23057
- bivariant = bivariant || kind === SyntaxKind.MethodDeclaration || kind === SyntaxKind.MethodSignature || kind === SyntaxKind.Constructor;
23058
- applyToParameterTypes(source, target, inferFromContravariantTypes);
23059
- bivariant = saveBivariant;
23060
- }
23057
+ function inferFromSignature(source: Signature, target: Signature) {
23058
+ const saveBivariant = bivariant;
23059
+ const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown;
23060
+ // Once we descend into a bivariant signature we remain bivariant for all nested inferences
23061
+ bivariant = bivariant || kind === SyntaxKind.MethodDeclaration || kind === SyntaxKind.MethodSignature || kind === SyntaxKind.Constructor;
23062
+ applyToParameterTypes(source, target, inferFromContravariantTypes);
23063
+ bivariant = saveBivariant;
23061
23064
applyToReturnTypes(source, target, inferFromTypes);
23062
23065
}
23063
23066
@@ -31271,7 +31274,7 @@ namespace ts {
31271
31274
// returns a function type, we choose to defer processing. This narrowly permits function composition
31272
31275
// operators to flow inferences through return types, but otherwise processes calls right away. We
31273
31276
// use the resolvingSignature singleton to indicate that we deferred processing. This result will be
31274
- // propagated out and eventually turned into nonInferrableType (a type that is assignable to anything and
31277
+ // propagated out and eventually turned into silentNeverType (a type that is assignable to anything and
31275
31278
// from which we never make inferences).
31276
31279
if (checkMode & CheckMode.SkipGenericFunctions && !node.typeArguments && callSignatures.some(isGenericFunctionReturningFunction)) {
31277
31280
skippedGenericFunction(node, checkMode);
@@ -31906,8 +31909,8 @@ namespace ts {
31906
31909
const signature = getResolvedSignature(node, /*candidatesOutArray*/ undefined, checkMode);
31907
31910
if (signature === resolvingSignature) {
31908
31911
// CheckMode.SkipGenericFunctions is enabled and this is a call to a generic function that
31909
- // returns a function type. We defer checking and return nonInferrableType .
31910
- return nonInferrableType ;
31912
+ // returns a function type. We defer checking and return silentNeverType .
31913
+ return silentNeverType ;
31911
31914
}
31912
31915
31913
31916
checkDeprecatedSignature(signature, node);
0 commit comments