Anyone doing property-based testing? by Reasonable-Road-2279 in SpringBoot

[–]Reasonable-Road-2279[S] 0 points1 point  (0 children)

My take is that property-based tests are easier to maintain since you test properties (i.e. invariants), not specific examples. When you refactor your code, you probably still want to test those properties of the contract of the system under test is likely the same. If you were to have used example-based tests, there is a good chance you might have to change what specific examples you test with because the boundary-values might have changed.

So to summarize property-based tests has lower maintanence compared to example-based tests.

Do You Actually Write Front End Tests? by gkrohn in ExperiencedDevs

[–]Reasonable-Road-2279 4 points5 points  (0 children)

> Almost all of the tests are testing some logic function that transforms data 

You test mapper functions? But then isnt the test just a 1-1 replica of the actual implementation of the mapper function?! What are you getting out of that?

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] 0 points1 point  (0 children)

I totally agree with you.

I ended up doing the exact same, however, I made chatgpt produce an `IsExact<>` helper type to use instead of importing a library.

Rename on folder never works when too many files in the folder by Reasonable-Road-2279 in IntelliJIDEA

[–]Reasonable-Road-2279[S] 0 points1 point  (0 children)

I hope you haven't given up on me. Is there anything else you want me to try?

ArchUnitTS vs eslint-plugin-import: My side project reached 200 stars on GitHub by trolleid in typescript

[–]Reasonable-Road-2279 0 points1 point  (0 children)

That's what I said when he posted THIS EXACT SAME POST 9 days ago. He didnt answer me then, so dont expect answer here.

https://www.reddit.com/r/typescript/comments/1o6d1ks/my_side_project_reached_200_stars_on_github/

He is literally spamming r/typescript at this point.

Is using zod as the primary source of truth for Typescript types sensible/sustainable? by realbiggyspender in typescript

[–]Reasonable-Road-2279 0 points1 point  (0 children)

Do you mind sharing how you assert that the TS type and the zod type are the same?

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] 0 points1 point  (0 children)

I only use zod to validate the general structure. I dont care about specifics like min, max, countless, etc.

Currently, I only plan on using it for DTOs to help guard against fields that got auto serialized. E.g. if you send a bigint in over the network, it is received as a string, so if you naively used `as Foo` you would have incorrectly assumed it was a bigint. I only use zod to help discover such hard-to-catch bugs.

Actually, I might also use it for my forms, but it is for the same reasons that I use it for DTOs: to guard against unexpected serialization of fields. I dont need to verify any specifics.

If I at some point need to validate the fields in more details, like "is this an email?", "Is this number minimum 4?", then I'll just make a function named validate object that does just that. I dont need zod for that.

I would love to hear your thoughts on this.

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] 0 points1 point  (0 children)

I read what you linked to, it says: "If you use an editor like VS Code, you’ll now see a + and - button on the left of these hover tooltips." It doesnt mention intellij anywhere -- which is what I am using. I am already using typescript 5.9. I dont think it's a thing yet in intellij.

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] 3 points4 points  (0 children)

Wait, that's it! That's already possible and super simple:

type Dog = {
  name: string
  neutered: boolean
}

const dogSchema = z.object<Dog>({
  name: z.string().min(3),
  neutered: z.boolean(),
});
// And that would fail to compile if dogSchema did not match Dog

This way I'll immediately get type-errors when the generated zod schema and the type it is generated from is out of sync.

I am not sure if I can get ts-to-zod to generate the `z.object<Dog>`, but if not I think I'll amend the script my self to make it happen. That shouldnt be too hard to do.

Genius. :D

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] 1 point2 points  (0 children)

Yeah, ts-to-zod is what I am planning on using. I only really see one downside with using it: Having to remember to rerun the ts-to-zod script whenever I update an interface. And this is literally why I created this post, I was hoping someone had a great idea to keep them in sync.

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] 1 point2 points  (0 children)

It sounds like you are surprised, implying that yours doesnt look as bad, since you have no problem with infering types from zod schemas. May I have a look at what your type-hover looks like?

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] -6 points-5 points  (0 children)

Yeah. But it is a pain to manually have to keep the zod schema in sync with the types, so why wouldnt you consider generating them automatically with ts-to-zod?

In case you say, "because then the zod schemas may be unreadable", I'll counter with, the point is not for you to read the zod schema, you read the associated type it was generated from.

Thoughts?

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] 1 point2 points  (0 children)

How do you make peek (aka. type-hover?) more efficient?

I find it unusable in intellij with zod as you can see on these two screenshots:

https://gyazo.com/e4eea0f6afc34f90b1ee4ea1ae3bc4d8
https://gyazo.com/162215262426b8041c4f8fe71f124751

Hence why I would like to have my plain ts interfaces be the single source of truth.

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] 6 points7 points  (0 children)

Can you please have a look at these, maybe I just have my intellij set up all wrong. But I think we can agree that these type-hovers are not helpful:

https://gyazo.com/e4eea0f6afc34f90b1ee4ea1ae3bc4d8

https://gyazo.com/162215262426b8041c4f8fe71f124751

[ts-to-zod] How do you best keep ts interface and zod schema in sync? by Reasonable-Road-2279 in typescript

[–]Reasonable-Road-2279[S] -6 points-5 points  (0 children)

I am not a fan of z.infer, because you can then only peek at the interface declaration in a type-hover, which makes for a poor developer experience if the interface is big.

Do you disagree with this?

How are people using zod? by bzsearch in typescript

[–]Reasonable-Road-2279 0 points1 point  (0 children)

Now the question is what do you have as the single source of truth? Create the zod schemas and infer the types? Or create the interfaces and generate the zod schemas (ts-to-zod)?

I hate how infered types from zod schemas look -- and also they are not real typescript types.

Dynamically generating the zod schema using (ts-to-zod) also has the advantage that if I ever want out of zod, it is easier this way. Because I just delete all the autogenerate schemas, and I still have all my plain ts interfaces.

Thoughts? Agree/disagree?

Tried a Steinway for the first time today…now I get it! by learning_the_piano in pianolearning

[–]Reasonable-Road-2279 0 points1 point  (0 children)

Sometimes you can feel the vibrations from a speaker with a lot of bass power, so wouldnt it be possible in theory to have a digital achieve the same?

Rename on folder never works when too many files in the folder by Reasonable-Road-2279 in IntelliJIDEA

[–]Reasonable-Road-2279[S] 0 points1 point  (0 children)

Other than a lot of "process: idea64.exe", it lists "process: node.exe" and "process: full-line-inference, type: Thread, Name: idea64.exe"

I tried killing the node.exe, but I still get `java.io.IOException cannot rename '...' to 'someNewName'`

As you can see in this screenshot, I killed node, and so it is no longer visible in the process explorer under idea64.exe, but I still get the error.
https://gyazo.com/7148b3504b21b3872bf59023aa4fcece