Effect-TS / schema

Modeling the schema of data structures as first-class values

Home Page:https://effect.website

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optional literals with defaults do not type check

vecerek opened this issue · comments

What version of @effect/schema is running?

0.55.0

What steps can reproduce the bug?

import * as Schema from "@effect/schema/Schema";

Schema.struct({
  a: Schema.optional(
    Schema.literal("a"),
    { exact: true, default: () => "a" }
//    ^^^^
//    No overload matches this call.
//      The last overload gave the following error.
//        Argument of type '{ exact: boolean; default: () => string; }' is not assignable to parameter of type '{ readonly as: "Option"; }'.
//        Object literal may only specify known properties, and 'exact' does not exist in type '{ readonly as: "Option"; }'.ts(2769)
  )
})

What is the expected behavior?

The code type checks.

What do you see instead?

No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ exact: boolean; default: () => string; }' is not assignable to parameter of type '{ readonly as: "Option"; }'.
      Object literal may only specify known properties, and 'exact' does not exist in type '{ readonly as: "Option"; }'.

Additional information

No response

add as const: () => "a" as const

That fixes it, thanks!