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

Method narrowTypeByTypeFacts

internal/checker/flow.go:673–688  ·  view source on GitHub ↗
(t *Type, impliedType *Type, facts TypeFacts)

Source from the content-addressed store, hash-verified

671}
672
673func (c *Checker) narrowTypeByTypeFacts(t *Type, impliedType *Type, facts TypeFacts) *Type {
674 return c.mapType(t, func(t *Type) *Type {
675 switch {
676 case c.isTypeRelatedTo(t, impliedType, c.strictSubtypeRelation):
677 if c.hasTypeFacts(t, facts) {
678 return t
679 }
680 return c.neverType
681 case c.isTypeSubtypeOf(impliedType, t):
682 return impliedType
683 case c.hasTypeFacts(t, facts):
684 return c.getIntersectionType([]*Type{t, impliedType})
685 }
686 return c.neverType
687 })
688}
689
690func (c *Checker) narrowTypeByDiscriminantProperty(t *Type, access *ast.Node, operator ast.Kind, value *ast.Node, assumeTrue bool) *Type {
691 if (operator == ast.KindEqualsEqualsEqualsToken || operator == ast.KindExclamationEqualsEqualsToken) && t.flags&TypeFlagsUnion != 0 {

Callers 1

narrowTypeByTypeNameMethod · 0.95

Calls 5

mapTypeMethod · 0.95
isTypeRelatedToMethod · 0.95
hasTypeFactsMethod · 0.95
isTypeSubtypeOfMethod · 0.95
getIntersectionTypeMethod · 0.95

Tested by

no test coverage detected