-
Notifications
You must be signed in to change notification settings - Fork 149
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
Transform type keys in Record #919
Comments
@s-egea Hi! Sorry for the delay.
Hmmm, I'm not too sure about this. There isn't really an mechanism that would enable Record keys to be transformed (either for Encode/Decode), and the best next thing I can think of would be to discard the Transform when applied to keys (which may not be expected). Currently, the Record type only accepts a few known key types (string, number, union literal, template literal, generally any type that can naturally encode the type as part of the const K = T.Transform(T.String())
.Decode((v) => v)
.Encode((v) => v);
const S = T.Record(K, T.String()); // S is T.TNever Will close out this issue for now as I don't think there is much that can be done to resolve in a satisfactory way that makes sense for Transforms (as they currently are). But I'll drop a suggestion tag on this issue and revisit in future. There are planned updates to Transforms (and validation) in later releases, and there may be potential to explore this under a updated validation infrastructure. Cheers! |
No worries about the delay! I’m just dropping some ideas on how I thought it could be implemented. I apologize in advance if my understanding is incorrect or incomplete. As I find it difficult to explain my ideas using text only, I will share two drawings instead:
I'm aware that this use case is not very common, so I’m perfectly fine continuing with my (type) patch for now.
Note that my current project makes extensive use of Transform types, so I will be happy to share some feedback and pain points I encountered. Thanks again! |
Behavior
Hi, I've encountered the following behavior using TypeBox
It seems that using Transform types in
Record
keys is not yet supported.Patch
For now I've applied the following patch to make my code work (my decoding function is just the identity function, so all I really need is the
Static
type to work).I wonder if it would make sense to add support for using Transform types in
Record
keys (not just at the type level) ?Thanks for your answer !
The text was updated successfully, but these errors were encountered: