Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript
https://effect.website
MIT License
7.71k stars 245 forks source link

Fields from schema pick do not have the same properties with the original #3829

Closed ciokan closed 1 month ago

ciokan commented 1 month ago

What version of Effect is running?

3.9.2

What steps can reproduce the bug?

Playground: https://effect.website/play#29f8ed0cac13

In short: it seems that the derived schema using pick has different field properties from the original

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

gcanti commented 1 month ago

There are no bugs, in appRouter2 you are using Schema.encode and the encoding side of SelectStatusPageSchema is { readonly description?: string | null; }:

import { Schema } from "effect"

class StatusPage extends Schema.Class<StatusPage>("StatusPage")({
  id: Schema.String.pipe(Schema.nonEmptyString()),
  description: Schema.optionalWith(
    Schema.String.pipe(Schema.nonEmptyString()),
    { exact: true, nullable: true }
  )
}) {}

const SelectStatusPageSchema = Schema.Struct(StatusPage.fields).pick("description")

/*
const plainSchema: Schema.Schema<{
    readonly description?: string;
}, {
    readonly description?: string | null;
}, never>
*/
const plainSchema = Schema.asSchema(SelectStatusPageSchema)