Propagate nonInferrableType in &&, || and ?? operators (#38035)

* Propagate nonInferrableType in &&, || and ?? operators

* Add regression test

* Simpler solution: getTypeFacts(neverType) should return TypeFacts.None
This commit is contained in:
Anders Hejlsberg
2020-04-20 11:04:24 -07:00
committed by GitHub
parent 38f8db5e45
commit 5d78cbdbbd
5 changed files with 50 additions and 1 deletions

View File

@@ -19390,6 +19390,9 @@ namespace ts {
if (flags & TypeFlags.NonPrimitive) {
return strictNullChecks ? TypeFacts.ObjectStrictFacts : TypeFacts.ObjectFacts;
}
if (flags & TypeFlags.Never) {
return TypeFacts.None;
}
if (flags & TypeFlags.Instantiable) {
return getTypeFacts(getBaseConstraintOfType(type) || unknownType);
}
@@ -19626,7 +19629,7 @@ namespace ts {
const filtered = filter(types, f);
return filtered === types ? type : getUnionTypeFromSortedList(filtered, (<UnionType>type).objectFlags);
}
return f(type) ? type : neverType;
return type.flags & TypeFlags.Never || f(type) ? type : neverType;
}
function countTypes(type: Type) {