MCPcopy Create free account
hub / github.com/microsoft/typescript-go / narrowTypeByCallExpression

Method narrowTypeByCallExpression

internal/checker/flow.go:444–467  ·  view source on GitHub ↗
(f *FlowState, t *Type, callExpression *ast.Node, assumeTrue bool)

Source from the content-addressed store, hash-verified

442}
443
444func (c *Checker) narrowTypeByCallExpression(f *FlowState, t *Type, callExpression *ast.Node, assumeTrue bool) *Type {
445 if c.hasMatchingArgument(callExpression, f.reference) {
446 var predicate *TypePredicate
447 if assumeTrue || !isCallChain(callExpression) {
448 signature := c.getEffectsSignature(callExpression)
449 if signature != nil {
450 predicate = c.getTypePredicateOfSignature(signature)
451 }
452 }
453 if predicate != nil && (predicate.kind == TypePredicateKindThis || predicate.kind == TypePredicateKindIdentifier) {
454 return c.narrowTypeByTypePredicate(f, t, predicate, callExpression, assumeTrue)
455 }
456 }
457 if c.containsMissingType(t) && ast.IsAccessExpression(f.reference) && ast.IsPropertyAccessExpression(callExpression.Expression()) {
458 callAccess := callExpression.Expression()
459 if c.isMatchingReference(f.reference.Expression(), c.getReferenceCandidate(callAccess.Expression())) && ast.IsIdentifier(callAccess.Name()) && callAccess.Name().Text() == "hasOwnProperty" && len(callExpression.Arguments()) == 1 {
460 argument := callExpression.Arguments()[0]
461 if accessedName, ok := c.getAccessedPropertyName(f.reference); ok && ast.IsStringLiteralLike(argument) && accessedName == argument.Text() {
462 return c.getTypeWithFacts(t, core.IfElse(assumeTrue, TypeFactsNEUndefined, TypeFactsEQUndefined))
463 }
464 }
465 }
466 return t
467}
468
469func (c *Checker) narrowTypeByBinaryExpression(f *FlowState, t *Type, expr *ast.BinaryExpression, assumeTrue bool) *Type {
470 switch expr.OperatorToken.Kind {

Callers 1

narrowTypeMethod · 0.95

Calls 15

hasMatchingArgumentMethod · 0.95
getEffectsSignatureMethod · 0.95
isMatchingReferenceMethod · 0.95
getReferenceCandidateMethod · 0.95
getTypeWithFactsMethod · 0.95
IsAccessExpressionFunction · 0.92
IsIdentifierFunction · 0.92
IsStringLiteralLikeFunction · 0.92

Tested by

no test coverage detected