From Discord: `Schema.omit()` Overlooks `Schema.fromKey` Properties: Intentional Behavior?
Summary
Summary
-
Issue Raised: The user
jessekellynoticed thatSchema.omit()in the Effect-TS library seems to ignore properties defined usingSchema.fromKey. This behavior is problematic for them as they expectomitto work uniformly regardless of how properties are defined within the schema. -
Initial Response:
gcantiexplained thatSchema.omit()can only omit keys that are present in both the input (I) and output (A) types of the schema. This is because, at the type level, there isn't enough information to keep the keys connected otherwise. -
Clarification:
jessekellyargued thatomitshould work similarly to manually omitting fields from the schema's fields, which works for their purposes. They suggested thatSchema.omitcould be defined in terms ofschema.fieldsandStruct.omit(). -
Further Explanation:
gcanticlarified that the current signature ofSchema.omitdoesn't allow it to seePropertySignaturesbecause it operates on the schema as a whole, not on its individual fields. -
Potential Solution:
gcantisuggested that handling structs as a special case withinSchema.omitcould address the issue, as omitting (and picking) from a struct is a notable use case.
Key Takeaways
- Current Limitation:
Schema.omitcannot omit keys that are defined usingSchema.fromKeybecause it doesn't have enough type-level information to connect the keys. - Desired Behavior: Users expect
Schema.omitto work uniformly, regardless of how properties are defined within the schema. - Potential Solutions:
- Extend the type signature of
Schema.omitto handle structs as a special case. - Introduce a new function, such as
Schema.omitField, to handle this specific use case.
- Extend the type signature of
- User Expectation: Users prefer to think about the decoded type and want to avoid refactoring their code due to changes in property names from the backend.
This discussion highlights the need for more flexible and transparent handling of schema transformations in the Effect-TS library.
Discord thread
https://discord.com/channels/795981131316985866/1258027788959481957