fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
5.91k stars 180 forks source link

Return type of `getDotPath` function is `null` for schemas with `pipeAsync` #814

Closed declanlscott closed 20 hours ago

declanlscott commented 1 week ago

Thank you for creating this excellent library! This is the first time I've come across any issue after using valibot for some time.

Issue

When using the getDotPath function with an async pipe schema, the resulting return type is null. I have verified this is not the behavior when using a non-async pipe schema.

Minimal reproduction

I also created a minimal reproduction in the playground where you can see hovering over the issuePaths variable reveals null[]. The function returns the correct values, as shown in the logs after running the playground, but the return type is not consistent with this.

Investigation

I did some preliminary investigation and it seems like the condition in the first line of the IssueDotPath type definition fails, eventually resolving the type to never. I'm not sure why this would be happening though?

If this is the expected behavior or if I'm missing something in my implementation, please let me know!

fabian-hiller commented 1 week ago

This is a bug. Thank you for creating this PR. It seems to happen whenever pipeAsync contains an async action, but I think I could fix it by changing the following code in the IssueDotPath type:

-TSchema extends SchemaWithPipe<infer TPipe> | SchemaWithPipeAsync<infer TPipe>
-  ? IssueDotPath<FirstTupleItem<TPipe>>
-  : ...

+TSchema extends SchemaWithPipe<infer TPipe>
+  ? IssueDotPath<FirstTupleItem<TPipe>>
+  : TSchema extends SchemaWithPipeAsync<infer TPipe>
+    ? IssueDotPath<FirstTupleItem<TPipe>>
+    : ...

Before releasing a new version, I need to investigate if the same happens for other parts of the IssueDotPath type.

fabian-hiller commented 1 week ago

This will be fixed with the next release

fabian-hiller commented 20 hours ago

v0.42.0 is available