(type, candidate, assumeTrue, isRelated)
| 71279 | return getNarrowedType(type, targetType, assumeTrue, isTypeDerivedFrom); |
| 71280 | } |
| 71281 | function getNarrowedType(type, candidate, assumeTrue, isRelated) { |
| 71282 | if (!assumeTrue) { |
| 71283 | return filterType(type, function (t) { return !isRelated(t, candidate); }); |
| 71284 | } |
| 71285 | // If the current type is a union type, remove all constituents that couldn't be instances of |
| 71286 | // the candidate type. If one or more constituents remain, return a union of those. |
| 71287 | if (type.flags & 1048576 /* TypeFlags.Union */) { |
| 71288 | var assignableType = filterType(type, function (t) { return isRelated(t, candidate); }); |
| 71289 | if (!(assignableType.flags & 131072 /* TypeFlags.Never */)) { |
| 71290 | return assignableType; |
| 71291 | } |
| 71292 | } |
| 71293 | // If the candidate type is a subtype of the target type, narrow to the candidate type. |
| 71294 | // Otherwise, if the target type is assignable to the candidate type, keep the target type. |
| 71295 | // Otherwise, if the candidate type is assignable to the target type, narrow to the candidate |
| 71296 | // type. Otherwise, the types are completely unrelated, so narrow to an intersection of the |
| 71297 | // two types. |
| 71298 | return isTypeSubtypeOf(candidate, type) ? candidate : |
| 71299 | isTypeAssignableTo(type, candidate) ? type : |
| 71300 | isTypeAssignableTo(candidate, type) ? candidate : |
| 71301 | getIntersectionType([type, candidate]); |
| 71302 | } |
| 71303 | function narrowTypeByCallExpression(type, callExpression, assumeTrue) { |
| 71304 | if (hasMatchingArgument(callExpression, reference)) { |
| 71305 | var signature = assumeTrue || !ts.isCallChain(callExpression) ? getEffectsSignature(callExpression) : undefined; |
no test coverage detected
searching dependent graphs…