(type, predicate, callExpression, assumeTrue)
| 71321 | return type; |
| 71322 | } |
| 71323 | function narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue) { |
| 71324 | // Don't narrow from 'any' if the predicate type is exactly 'Object' or 'Function' |
| 71325 | if (predicate.type && !(isTypeAny(type) && (predicate.type === globalObjectType || predicate.type === globalFunctionType))) { |
| 71326 | var predicateArgument = getTypePredicateArgument(predicate, callExpression); |
| 71327 | if (predicateArgument) { |
| 71328 | if (isMatchingReference(reference, predicateArgument)) { |
| 71329 | return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf); |
| 71330 | } |
| 71331 | if (strictNullChecks && assumeTrue && optionalChainContainsReference(predicateArgument, reference) && |
| 71332 | !(getTypeFacts(predicate.type) & 65536 /* TypeFacts.EQUndefined */)) { |
| 71333 | type = getTypeWithFacts(type, 2097152 /* TypeFacts.NEUndefinedOrNull */); |
| 71334 | } |
| 71335 | var access = getDiscriminantPropertyAccess(predicateArgument, type); |
| 71336 | if (access) { |
| 71337 | return narrowTypeByDiscriminant(type, access, function (t) { return getNarrowedType(t, predicate.type, assumeTrue, isTypeSubtypeOf); }); |
| 71338 | } |
| 71339 | } |
| 71340 | } |
| 71341 | return type; |
| 71342 | } |
| 71343 | // Narrow the given type based on the given expression having the assumed boolean value. The returned type |
| 71344 | // will be a subtype or the same type as the argument. |
| 71345 | function narrowType(type, expr, assumeTrue) { |
no test coverage detected
searching dependent graphs…