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

Method inferFromMatchingTypes

internal/checker/inference.go:393–412  ·  view source on GitHub ↗
(n *InferenceState, sources []*Type, targets []*Type, matches func(c *Checker, s *Type, t *Type) bool)

Source from the content-addressed store, hash-verified

391}
392
393func (c *Checker) inferFromMatchingTypes(n *InferenceState, sources []*Type, targets []*Type, matches func(c *Checker, s *Type, t *Type) bool) ([]*Type, []*Type) {
394 var matchedSources []*Type
395 var matchedTargets []*Type
396 for _, t := range targets {
397 for _, s := range sources {
398 if matches(c, s, t) {
399 c.inferFromTypes(n, s, t)
400 matchedSources = core.AppendIfUnique(matchedSources, s)
401 matchedTargets = core.AppendIfUnique(matchedTargets, t)
402 }
403 }
404 }
405 if len(matchedSources) != 0 {
406 sources = core.Filter(sources, func(t *Type) bool { return !slices.Contains(matchedSources, t) })
407 }
408 if len(matchedTargets) != 0 {
409 targets = core.Filter(targets, func(t *Type) bool { return !slices.Contains(matchedTargets, t) })
410 }
411 return sources, targets
412}
413
414func (c *Checker) inferToMultipleTypes(n *InferenceState, source *Type, targets []*Type, targetFlags TypeFlags) {
415 typeVariableCount := 0

Callers 1

inferFromTypesMethod · 0.95

Calls 5

inferFromTypesMethod · 0.95
AppendIfUniqueFunction · 0.92
FilterFunction · 0.92
lenFunction · 0.85
ContainsMethod · 0.65

Tested by

no test coverage detected