fabian-hiller / valibot

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

Compiled type for actions missing typing for 'requirement' in ErrorMessage #607

Closed adamayres closed 1 month ago

adamayres commented 1 month ago

Thanks for the great lib! I noticed that the compiled types for actions lose the typing for the requirement in the function callback format of ErrorMessage.

Repro:

https://stackblitz.com/edit/typescript-4u6iog?file=index.ts

image

For example, the compiled type of minLength is:

declare function minLength<TInput extends string | any[], TRequirement extends number>(requirement: TRequirement, message?: ErrorMessage): MinLengthValidation<TInput, TRequirement>;

Note the typing on ErrorMessage lost it's generic parameters.

In the source code this type appears to be properly passed.

minLength

https://github.com/fabian-hiller/valibot/blob/2bdb2c8cb2228cc9d11776a60ba7e380caaece97/library/src/actions/minLength/minLength.ts#L90-L99

ErrorMessage

https://github.com/fabian-hiller/valibot/blob/2bdb2c8cb2228cc9d11776a60ba7e380caaece97/library/src/types/other.ts#L22-L24

BaseIssue

https://github.com/fabian-hiller/valibot/blob/2bdb2c8cb2228cc9d11776a60ba7e380caaece97/library/src/types/issue.ts#L55-L83

fabian-hiller commented 1 month ago

This should be fixed in the RC we released last week. Have a look at this playground.

adamayres commented 1 month ago

Thanks for the quick response, looks good in the RC.