effect icon indicating copy to clipboard operation
effect copied to clipboard

From Discord: `Schema.omit()` Overlooks `Schema.fromKey` Properties: Intentional Behavior?

Open effect-bot opened this issue 1 year ago • 0 comments

Summary

Summary

  1. Issue Raised: The user jessekelly noticed that Schema.omit() in the Effect-TS library seems to ignore properties defined using Schema.fromKey. This behavior is problematic for them as they expect omit to work uniformly regardless of how properties are defined within the schema.

  2. Initial Response: gcanti explained that Schema.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.

  3. Clarification: jessekelly argued that omit should work similarly to manually omitting fields from the schema's fields, which works for their purposes. They suggested that Schema.omit could be defined in terms of schema.fields and Struct.omit().

  4. Further Explanation: gcanti clarified that the current signature of Schema.omit doesn't allow it to see PropertySignatures because it operates on the schema as a whole, not on its individual fields.

  5. Potential Solution: gcanti suggested that handling structs as a special case within Schema.omit could address the issue, as omitting (and picking) from a struct is a notable use case.

Key Takeaways

  • Current Limitation: Schema.omit cannot omit keys that are defined using Schema.fromKey because it doesn't have enough type-level information to connect the keys.
  • Desired Behavior: Users expect Schema.omit to work uniformly, regardless of how properties are defined within the schema.
  • Potential Solutions:
    • Extend the type signature of Schema.omit to handle structs as a special case.
    • Introduce a new function, such as Schema.omitField, to handle this specific use case.
  • 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

effect-bot avatar Jul 03 '24 13:07 effect-bot