Allow boolean literals to be generated from contextual types again (#21503)

* Allow boolean literals to be generated from contextual types again

* Update fourslash test
This commit is contained in:
Wesley Wigham
2018-02-01 12:34:16 -08:00
committed by GitHub
parent 24476966e2
commit 058b2f7f11
93 changed files with 614 additions and 316 deletions

View File

@@ -18978,13 +18978,9 @@ namespace ts {
function isLiteralOfContextualType(candidateType: Type, contextualType: Type): boolean {
if (contextualType) {
if (contextualType.flags & TypeFlags.UnionOrIntersection && !(contextualType.flags & TypeFlags.Boolean)) {
// If the contextual type is a union containing both of the 'true' and 'false' types we
// don't consider it a literal context for boolean literals.
if (contextualType.flags & TypeFlags.UnionOrIntersection) {
const types = (<UnionType>contextualType).types;
return some(types, t =>
!(t.flags & TypeFlags.BooleanLiteral && containsType(types, trueType) && containsType(types, falseType)) &&
isLiteralOfContextualType(candidateType, t));
return some(types, t => isLiteralOfContextualType(candidateType, t));
}
if (contextualType.flags & TypeFlags.TypeVariable) {
// If the contextual type is a type variable constrained to a primitive type, consider