Optional literals with defaults do not type check
vecerek opened this issue · comments
Attila Večerek commented
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
Giulio Canti commented
add as const
: () => "a" as const
Attila Večerek commented
That fixes it, thanks!