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)
| 2372 | // For example, when a variable of type number | string | boolean is assigned a value of type number | boolean, |
| 2373 | // we remove type string. |
| 2374 | func (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 | |
| 2390 | func (c *Checker) getAssignmentReducedTypeWorker(declaredType *Type, assignedType *Type) *Type { |
| 2391 | filteredType := c.filterType(declaredType, func(t *Type) bool { |
no test coverage detected