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

Method getNullableType

internal/checker/checker.go:18563–18574  ·  view source on GitHub ↗

Add undefined or null or both to a type if they are missing.

(t *Type, flags TypeFlags)

Source from the content-addressed store, hash-verified

18561
18562// Add undefined or null or both to a type if they are missing.
18563func (c *Checker) getNullableType(t *Type, flags TypeFlags) *Type {
18564 missing := (flags & ^t.flags) & (TypeFlagsUndefined | TypeFlagsNull)
18565 switch {
18566 case missing == 0:
18567 return t
18568 case missing == TypeFlagsUndefined:
18569 return c.getUnionType([]*Type{t, c.undefinedType})
18570 case missing == TypeFlagsNull:
18571 return c.getUnionType([]*Type{t, c.nullType})
18572 }
18573 return c.getUnionType([]*Type{t, c.undefinedType, c.nullType})
18574}
18575
18576func (c *Checker) GetNonNullableType(t *Type) *Type {
18577 if c.strictNullChecks {

Callers 5

getCommonSupertypeMethod · 0.95
checkImportAttributesMethod · 0.95

Calls 1

getUnionTypeMethod · 0.95

Tested by

no test coverage detected