Effect CommunityEC
Effect Community3y ago
32 replies
Kristian Notari

Dealing with Tagged Structs in TypeScript

I have a list of tagged structs and I want to count occurrences for some of the tags and to concatenate some of their internal properties to a string for other tags. My first thought was to go for groupBy, but that return string keys instead of the tags (obviously). What I'd need is a Partial Record but then it doesn't play nicely with Record API.

Example:
interface A extends Data.Case {
    _tag: "A"
    a: number
}
const A = Data.tagged<A>(`A`)
interface B extends Data.Case {
    _tag: "B"
    b: string
}
const B = Data.tagged<B>(`B`)

declare const mylist: (A | B)[]

declare const wanted: {
   a: number
   b: string
}
Was this page helpful?