Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isFoo Functions should return an error message about which fields are missing or of wrong type #185

Open
juliandm opened this issue Mar 8, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@juliandm
Copy link

juliandm commented Mar 8, 2022

currently the generated functions just return a Boolean value. However in cases where ts-auto-guard is used for user feedback, a simple yes or no is not sufficient. A path to the faulty attributes would be better

{
 "isWellDefined": true
}

success response

{
 "isWellDefined": false,
 "faultyPaths": [".first.second.third", ".second.foo.bar"]
}

faulty example, could be even more specific about, which type was expected etc..

@juliandm
Copy link
Author

Although i like the concept of ts-auto-guard i solved it now by combining two other more standardised open source projects:

  1. generate a json schema of your ts types with https://github.com/vega/ts-json-schema-generator
  2. put this schema into ajv schema validator https://github.com/ajv-validator/ajv

works beautifully and also template literals and other advanced features of ts are worked on.

@rhys-vdw
Copy link
Owner

@juliandm you can use debug mode to information about the first field that failed, however it is not intended for production.

This library is not a validation library, it generates type guards, which conventionally do not give more information other than is or is not a type.

That said when I first started working on this I did intend to create an option to generate validators, which is why it needs type-guard in the comment annotation (so that I could later add type-validator etc.) But if you're looking for runtime type validator you're better off using a library that explicitly has that as one of its goals.

I'll leave this issue open for now in case there's any more discussion.

@rhys-vdw rhys-vdw added the enhancement New feature or request label Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants