mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Always use strict rules for contravariant inferences
This commit is contained in:
@@ -8129,8 +8129,9 @@ namespace ts {
|
||||
if (inferTypeParameters) {
|
||||
const inferences = map(inferTypeParameters, createInferenceInfo);
|
||||
// We don't want inferences from constraints as they may cause us to eagerly resolve the
|
||||
// conditional type instead of deferring resolution.
|
||||
inferTypes(inferences, checkType, extendsType, InferencePriority.NoConstraints);
|
||||
// conditional type instead of deferring resolution. Also, we always want strict function
|
||||
// types rules (i.e. proper contravariance) for inferences.
|
||||
inferTypes(inferences, checkType, extendsType, InferencePriority.NoConstraints | InferencePriority.AlwaysStrict);
|
||||
// We infer 'never' when there are no candidates for a type parameter
|
||||
const inferredTypes = map(inferences, inference => getTypeFromInference(inference) || neverType);
|
||||
const inferenceMapper = createTypeMapper(inferTypeParameters, inferredTypes);
|
||||
@@ -11510,7 +11511,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function inferFromContravariantTypes(source: Type, target: Type) {
|
||||
if (strictFunctionTypes) {
|
||||
if (strictFunctionTypes || priority & InferencePriority.AlwaysStrict) {
|
||||
contravariant = !contravariant;
|
||||
inferFromTypes(source, target);
|
||||
contravariant = !contravariant;
|
||||
|
||||
@@ -3884,6 +3884,7 @@ namespace ts {
|
||||
MappedType = 1 << 1, // Reverse inference for mapped type
|
||||
ReturnType = 1 << 2, // Inference made from return type of generic function
|
||||
NoConstraints = 1 << 3, // Don't infer from constraints of instantiable types
|
||||
AlwaysStrict = 1 << 4, // Always use strict rules for contravariant inferences
|
||||
}
|
||||
|
||||
export interface InferenceInfo {
|
||||
|
||||
Reference in New Issue
Block a user