Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From Discord: Issue with Schema annotations and context in TypeScript #3165

Closed
effect-bot opened this issue Jul 4, 2024 · 0 comments · Fixed by #3162
Closed

From Discord: Issue with Schema annotations and context in TypeScript #3165

effect-bot opened this issue Jul 4, 2024 · 0 comments · Fixed by #3162
Assignees
Labels
enhancement New feature or request schema

Comments

@effect-bot
Copy link

Summary

Summary of the Discussion

  1. Initial Issue:

    • User (jessekelly): Encountered an issue where Schema.annotations({ message: Effect }) wasn't picking up on the context in TypeScript.
    • Code Example: Provided a code snippet where the message was defaulting to "default" instead of using the context.
  2. Solution Provided:

    • gcanti: Suggested using formatError explicitly instead of formatIssueSync to make the context visible.
    • Updated Code: Provided an updated code snippet that resolved the issue.
  3. Further Discussion:

    • michaelarnaldi: Asked if message could see the context when evaluated in a fiber.
    • dilame_bowzee: Suggested that Schema.filter should accept a function returning an Effect for better i18n support.
    • jessekelly: Agreed and mentioned using transformOrFail for custom filters.
    • gcanti: Explained that filter cannot return an Effect because it models an AST.Refinement, but suggested creating a filterEffect function that builds upon transformOrFail.
  4. Implementation of filterEffect:

    • gcanti: Provided a code example for filterEffect that builds upon transformOrFail.
  5. Discussion on Extending Refinement:

    • michaelarnaldi: Asked if it was possible to extend Refinement to support effects.
    • gcanti: Mentioned that extending Refinement would have significant implications and that currently, "Effect" is compartmentalized in AST.Transformations.
  6. PR Suggestion:

    • dilame_bowzee: Offered to create a PR with the filterEffect function.
    • gcanti: Responded that they have some spare time and can work on it.

Key Takeaways

  1. Explicit Use of formatError: When dealing with schema annotations that need to pick up context, use formatError explicitly.
  2. Custom Filters with Effects: While filter cannot return an Effect, a custom filterEffect function can be created using transformOrFail.
  3. Impact of Extending Refinement: Extending Refinement to support effects would have significant implications and needs careful evaluation.
  4. Community Collaboration: The discussion shows active community collaboration, with members offering to create PRs and contribute code examples.

Discord thread

https://discord.com/channels/795981131316985866/1243877438795288586

@gcanti gcanti added enhancement New feature or request schema labels Jul 4, 2024
@gcanti gcanti self-assigned this Jul 4, 2024
gcanti added a commit that referenced this issue Jul 4, 2024
@gcanti gcanti closed this as completed in 15967cf Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request schema
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants