Skip to content

Conversation

@Laurin-W
Copy link

@Laurin-W Laurin-W commented Nov 8, 2025

The PR adds utility types that can infer the TypeScript types from validation schemas.

This is the type inference part that is eventually intended to be used in moleculer to infer the parameter types of action handlers.

I modified the compile() function of the Validator so that the returned check function expects the TS type that was specified in the schema passed to compile().
If you prefer to not have this implemented with the check()/compile() function, let me know. We could also just export the utility types for external use (by moleculer).

Note that the inference types do not support all features that the validator does. For example, "email" or "uuid" are interpreted as string.
Also, type inference for validators with the considerNullAsAValue flag are not implemented (it does not seem to be a very common use case and the complexity would grow. Let me know if you think it should be implemented).

This is WIP.
The TS unit tests are not yet adapted (they will require // @ts-expect-error comments for check() calls with invalid objects).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant