From Discord: Extracting Tags from a Schema.Union of TaggedStructs
Summary
In this conversation, a user is trying to extract tags from a Schema.Union of TaggedStructs in a TypeScript project using the Effect Typescript library. Initially, the user attempts to map over the union members to extract _tag values, expecting an array of strings, but encounters an array of Schema.Tag[] instead. A suggestion is made to expose a _tag property directly on TaggedStruct, similar to other Tagged* APIs, to facilitate this extraction.
Key takeaways:
-
Enhancing
TaggedStructAPI: The_tagproperty should be exposed on theTaggedStructto allow easy extraction of tags, making it consistent with otherTagged*APIs. -
Refactoring Approach: The user refactored their code to use an enum for tags instead of plain strings, allowing iteration over the enum to retrieve all tags efficiently.
-
Schema and Tagging in Effect: Using schemas and well-defined tags (via enum or similar structures) can help organize and manage complex data structures effectively in TypeScript projects.
Overall, the conversation highlights a practical approach to dealing with type system limitations and API improvements in a TypeScript schema management library.
Discord thread
https://discord.com/channels/795981131316985866/1371410719689670666