(union: InferredShape, branch: InferredShape)
| 152 | }; |
| 153 | |
| 154 | const addUnionBranch = (union: InferredShape, branch: InferredShape): InferredShape => { |
| 155 | if (isUnknown(union) || isUnknown(branch)) return UNKNOWN; |
| 156 | const branches = [...(union.anyOf ?? [union])]; |
| 157 | const index = branches.findIndex((existing) => existing.type === branch.type); |
| 158 | const next = |
| 159 | index === -1 |
| 160 | ? [...branches, branch] |
| 161 | : branches.map((existing, i) => (i === index ? mergeShapes(existing, branch) : existing)); |
| 162 | if (next.length > MAX_ANYOF) return UNKNOWN; |
| 163 | return next.length === 1 ? (next[0] ?? UNKNOWN) : { anyOf: next }; |
| 164 | }; |
| 165 | |
| 166 | /** |
| 167 | * One tool's accumulated muscle memory: the merged shape plus enough |
no test coverage detected