Effect CommunityEC
Effect Community3mo ago
7 replies
Devin Jameson

Question about `Struct.evolve` and Type Widening Prevention

Question about Struct.evolve and type widening:

const Letter = S.Literal("A", "B", "C")

type Foo = {
  letter: typeof Letter.Type
}

const foo: Foo = {
  letter: "A",
}

const nextFoo: Foo = Struct.evolve(foo, {
  letter: () => "B",
})

// Diagnostics:
// 1. Type '{ letter: string; }' is not assignable to type 'Foo'.
//      Types of property 'letter' are incompatible.
//        Type 'string' is not assignable to type '"A" | "B" | "C"'. [2322]


Can Struct.evolve enforce that the type of nextFoo is the same as foo? And can it not widen string literal types (and other types that might be widened like tuples)?
Was this page helpful?