mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
No contextual typing from return types for boolean literals (#48380)
* No contextual typing from return types for boolean literals * Accept new baselines * Add regression tests
This commit is contained in:
@@ -26902,9 +26902,14 @@ namespace ts {
|
||||
return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
|
||||
}
|
||||
// For other purposes (e.g. determining whether to produce literal types) we only
|
||||
// incorporate inferences made from the return type in a function call.
|
||||
// incorporate inferences made from the return type in a function call. We remove
|
||||
// the 'boolean' type from the contextual type such that contextually typed boolean
|
||||
// literals actually end up widening to 'boolean' (see #48363).
|
||||
if (inferenceContext.returnMapper) {
|
||||
return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
|
||||
const type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
|
||||
return type.flags & TypeFlags.Union && containsType((type as UnionType).types, regularFalseType) && containsType((type as UnionType).types, regularTrueType) ?
|
||||
filterType(type, t => t !== regularFalseType && t !== regularTrueType) :
|
||||
type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user