Incorrect type for type/encodeSchema with Schema.declare
What version of Effect is running?
3.14.2
What steps can reproduce the bug?
basic issue is that a schema like this gives incorrect types for Schema.encodedSchema and Schema.typeSchema - because fundamentally both are gonna be the same as the original schema.
Schema.declare(
[],
{
decode() {
return function () {
return ParseResult.succeed(1);
};
},
encode() {
return function () {
return ParseResult.succeed("a");
};
},
},
{},
)
Here's a playground with a demo of the issue and my original use-case which lead me to discovering the issue https://effect.website/play#bc96e4ce0aef
Here's a discussion on your Discord server where I've initially reported the issue I was having, my use-case and how I've reached the core of the problem https://discord.com/channels/795981131316985866/1372606482985517056 My use-case was basically having a schema which can decode a HashMap from a string and back - decoding I do by myself, encoding I just delegate to Schema
What is the expected behavior?
I understand that there may not even be a solution here really
- There's no fixing
type/encodedSchemaso they give a schema with "expected" behavior - given howdeclareschemas are implemented I think it's straight up impossible. PerhapsSchema@4could address this - Perhaps the types could be corrected here so they at least represented what you actually get but that doesn't help much because
- because the way I've initially encountered the issue - I don't think point 2 would have helped much. So perhaps just some sort of disclaimer in docs?
What do you see instead?
I have solved my issue just by using HashMapFromSelf instead because then I get "consistent" encoding.
I would understand if you decide to just close this issue as not planned because there's no obvious solution here - but I thought it's still worth to bring your attention to.
Additional information
No response
My use-case was basically having a schema which can decode a HashMap from a string and back
Schema.declare is meant for defining new data types. In your case, you should use a transformation instead.
Should Schema.declare perhaps enforce then that it should return the same type from decoding and encoding?
I didn't want to use a transform because then I'm validating data twice - during transform(decoding from string) and then on the type-side schema, that seemed excessive to me. Any workarounds for this? I could only think of using declare