moltar / typescript-runtime-type-benchmarks

📊 Benchmark Comparison of Packages with Runtime Validation and TypeScript Support
https://moltar.github.io/typescript-runtime-type-benchmarks/
654 stars 63 forks source link

What about joi library? #818

Closed mihanizm56 closed 2 years ago

mihanizm56 commented 2 years ago

Hi, we use a lot of validation in browser runtime with "joi" library. Could you please add some benchmarks about this package?

moltar commented 2 years ago

Does it fit within the criteria?

mihanizm56 commented 2 years ago

Does it fit within the criteria?

The interface is different, but does the same things. Validate data and give error messages if data is not valid, and give the source data if valid. Based on its own schema syntax.

moltar commented 2 years ago

But does it do type guarding?

mihanizm56 commented 2 years ago

But does it do type guarding?

What do you actually mean?

moltar commented 2 years ago

Please see docs: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#typeof-type-guards

hoeck commented 2 years ago

Looks like Joi does not any type-guarding at all. Also its types are pretty basic when trying to enforce that a schema conforms to an interface:

typescript playground example

I am curious to see whether that affects performance, but then adding all the non-ts validation packages would probably make the benchmark results unreadable.

moltar commented 2 years ago

I don't think there is room for non-TS packages as there is just way too much prior art and I am not really particularly interested in anything non-TS anyways :)

I'm going to close this issue then.

mihanizm56 commented 2 years ago

Looks like Joi does not any type-guarding at all. Also its types are pretty basic when trying to enforce that a schema conforms to an interface:

typescript playground example

I am curious to see whether that affects performance, but then adding all the non-ts validation packages would probably make the benchmark results unreadable.

TS does not affects benchmarks at all because of building tools.

hoeck commented 2 years ago

TS does not affects benchmarks at all because of building tools.

You're right, but TS validators require a certain style of functional API for the type-inference to work. Maybe that influences performance in comparison to validators that are free to choose whatever API is the most performant, who knows.