Alternative naming convention/usage #1152
bjarketrux
started this conversation in
General
Replies: 1 comment
-
Hey 👋 I'm very sorry for my late reply, but I don't have a lot of time right now. Others should feel welcome to discuss your naming convention here, and once I have a little more time, I'll try to take a close look at it, provide feedback, and maybe add it to our docs. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I want to start a discussion and show how we use Valibot in our project - which does things a bit alternatively.
Our use case
We have an API in C# that our Angular application consumes via HTTP/JSON. All data is typed (TypeScript) but there was no actual validation on whether the TS and C# models align. Enter Valibot.
Example model (
product.model.ts
)Notice that
Product
is exported, use, and inherited from.Our requirements
myProp?
in TS and C# is different)Our schema definition (
product.schema.ts
)Why?
This is not really similar to the existing naming conventions. Here is why:
v.GenericSchema<Product>
). This will use our models (when parsing the JSON) not the inferred model. See the example below why this is preferable.*Raw
version of the schema. We need this for inheritance, see Merge objects.Consider this example:
The four
logProduct
function all work, but have a different signature.any
...satisfies
our model, but is not the same. Using VSCode's "extract method" onbook.product
would result in a function likelogProduct3
.Feedback
What do you think? Is there a better way than casting and having a
*Raw
exporting convention? Are we overly lazy and should just manually change the type when using "extract method"?Playground of examples
Beta Was this translation helpful? Give feedback.
All reactions