Skip to content

Serialized type is inlined #1

@samhh

Description

@samhh

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions