About using a generic pipe
Hello everyone,
I am writing a schema in which one of the fields requiredness can be played with. I've come up with this type
It does the job perfectly well. Now, if I want to use it for a schema, where the value should be sent if the value is null, I can use something like this:
But now, let's say I want to reuse this kind of logic in multiple other schemas. I thought about creating a pipe generator so that only the key needs to be set. Something like this:
that would help by rewriting
Profile
as
But then, the types resulting from the schema seem off. I guess this is more a TypeScript-related question than a Arktype one1 Reply
Yeah this kind of stuff can definitely be tricky.
Especially as your generic logic gets more complex, you will likely have to write the type-level logic manually using conditionals + mapped types to achieve what you want, then cast your implementation to that specified return type.
I wrote a bit about this in the docs here:
https://arktype.io/docs/faq#why-isnt-my-wrapper-generic-working