-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
sum-types-io-ts/test/type/index.ts
Line 9 in 33fa3b3
getCodecFromSerialized<A>({ A1: t.undefined, A2: t.number }) // $ExpectType Type<A, readonly ["A1", undefined] | readonly ["A2", number], unknown> |
Small repro in sum-types repo (to prove it's not (only) because we're reconstructing it):
type Serialized1<A extends Sum.AnyMember> = [Tag<A>, Value<A>] // this preserves the name
type Serialized2<A> = A extends Sum.AnyMember ? [Tag<A>, Value<A>] : never // this does not
type X = Sum.Member<'X', string> | Sum.Member<'Y', number>
declare const x1: Serialized1<X> // aliased
if (x1[0] === "X") x1[1] // string | number
declare const x2: Serialized2<X> // expanded
if (x2[0] === "X") x2[1] // string
We're using the conditional type to distribute over union members.
As an aside we should probably export Serialized
for both this and the fp-ts bindings repo. I also wonder if that would remove the need for some of the assertions?
Metadata
Metadata
Assignees
Labels
No labels