( casesByTag: CasesByTag )
| 6393 | * @since 4.0.0 |
| 6394 | */ |
| 6395 | export function TaggedUnion<const CasesByTag extends Record<string, Struct.Fields>>( |
| 6396 | casesByTag: CasesByTag |
| 6397 | ): TaggedUnion<{ readonly [K in keyof CasesByTag & string]: TaggedStruct<K, CasesByTag[K]> }> { |
| 6398 | const cases: any = {} |
| 6399 | const members: any = [] |
| 6400 | for (const key of Object.keys(casesByTag)) { |
| 6401 | const member = TaggedStruct(key, casesByTag[key]) |
| 6402 | InternalRecord.assignProperty(cases, key, member) |
| 6403 | members.push(member) |
| 6404 | } |
| 6405 | const union = Union(members) |
| 6406 | const { guards, isAnyOf, match } = toTaggedUnion("_tag")(union) |
| 6407 | return make(union.ast, { cases, isAnyOf, guards, match }) |
| 6408 | } |
| 6409 | |
| 6410 | /** |
| 6411 | * Type-level representation returned by {@link Opaque}. |
nothing calls this directly
no test coverage detected