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

Method getAssignmentReducedType

internal/checker/flow.go:2374–2388  ·  view source on GitHub ↗

Remove those constituent types of declaredType to which no constituent type of assignedType is assignable. For example, when a variable of type number | string | boolean is assigned a value of type number | boolean, we remove type string.

(declaredType *Type, assignedType *Type)

Source from the content-addressed store, hash-verified

2372// For example, when a variable of type number | string | boolean is assigned a value of type number | boolean,
2373// we remove type string.
2374func (c *Checker) getAssignmentReducedType(declaredType *Type, assignedType *Type) *Type {
2375 if declaredType == assignedType {
2376 return declaredType
2377 }
2378 if assignedType.flags&TypeFlagsNever != 0 {
2379 return assignedType
2380 }
2381 key := AssignmentReducedKey{id1: declaredType.id, id2: assignedType.id}
2382 result := c.assignmentReducedTypes[key]
2383 if result == nil {
2384 result = c.getAssignmentReducedTypeWorker(declaredType, assignedType)
2385 c.assignmentReducedTypes[key] = result
2386 }
2387 return result
2388}
2389
2390func (c *Checker) getAssignmentReducedTypeWorker(declaredType *Type, assignedType *Type) *Type {
2391 filteredType := c.filterType(declaredType, func(t *Type) bool {

Callers 1

Calls 1

Tested by

no test coverage detected