Function which receives a arktype's 'type'
I'm trying to do something like this:
But the parsedResponse isn't of type T, so how do I make this function accept as schema anything created using type({...})
6 Replies
try:
What do you mean that it's not of type
T
?
T
is not constrained here. Are you just not wanting to cast the return?
If that's the case it is likely a limitation of TS. It falls apart very quickly trying to do anything with generic types in a function.
See my recommendation here: https://discord.com/channels/957797212103016458/1289555141355241573/1289572327511687208
This will generally work in the default scope, but use type.Any
if you want it to accept all type instancesGood to know!
So casting here is ok
if I don't cast it, the parsedResponse has this type: finalizeDistillation<T, _distill<T, {
endpoint: "out";
}>>
Yeah like I said it's just a TS limitation it can't actually evaluate expressions on generic parameters
You can see how there's really no unique arktype logic here so that's not something I control
Because if you use the schema on its own it is inferred correctly
Yeah typescript with generic types in functions has never worked well
I understand, thanks!