TCMiranda / joi-extract-type

Provides native type extraction from Joi schemas for Typescript
MIT License
152 stars 27 forks source link

Move joi-extract-type into Joi's definitely typed file #25

Open guyellis opened 4 years ago

guyellis commented 4 years ago

I've created this as a separate Issue forking off of this comment because I don't want to hijack that conversation with this as a possible solution.

What if we moved joi-extract-type into the DefinitelyTyped file?

Quickly off the top of my head:

Advantages

Disadvantages

While I've phrased this as a proposal this is more of a discussion topic to brainstorm how we can solve this.

As a user of joi-extract-type we are finding this a valuable tool to manage our Joi Schemas as TypeScript types in our projects and think that the rest of the Joi/Typescript community would benefit from this as well. i.e. we now get both compile (transpile) and runtime protection from a single schema declaration.

What are your thoughts?

Tagging the Joi DefinitelyTyped contributors here for their opinions: @RecuencoJones @SimonSchick @Marsup @jaulz

TCMiranda commented 4 years ago

I would love that, as a "user".

In this case, there are also more solutions to exactly what joi-extract-type does. Probably, they should also be considered if we were to put a type extraction utility on Joi DefinitelyTyped.

Anyways, I in favor of that.

And if it is not possible for some reason, I feel it is really important to at least inform users better about the options they have if they are using typescript. Including some link to this repo (and similar ones) on the documentation for example.

SimonSchick commented 4 years ago

My main concern is the performance of these deep complex generics. Can we have some benchmark with and without these typings and huge schemas?

TCMiranda commented 4 years ago

That's a fair concern.

I think we can compare the time spent with a simple tsc to build a schema, infer its type and assign to some variable.

But i'm not sure if it correctly represents the overhead on developer tools like VSCode.

SimonSchick commented 4 years ago

DT provides detailed statistics on every build about performance and warns about significant regressions.

TCMiranda commented 4 years ago

What an awesome tool :open_mouth: Ok lets prepare a PR and see the impact. Thanks for this feedback.

guyellis commented 4 years ago

@SimonSchick - is there a way that we could setup the DefinitelyTyped file such that anybody using the Joi type definitions for only that would get what is currently there and that for those wanting joi-extract-type would get that + the joi-extract-type "extension?" (Trying to think of a way to not impact users that were not interested in this.)

Psuedo-coding my thoughts...

namespace JoiComplete {
  namespace Joi {
    // ... this is the existing definition
  }
  namespace JoiExtractType {
    // ... this is the joi-extract-type definition
    // ... if not referenced will not impact tsc transpile time...
    // ...I don't know if that's valid though?
  }
}
polson136 commented 4 years ago

I, for one, was expecting to get this from DefinitelyTyped and was rather disappointed when it didn't. For an example of a library that does provide this via DefinitelyTyped, see yup (I would use it, but I don't like many of the javascript design choices.)

TCMiranda commented 4 years ago

Hi, @polson136 yea you are right. This is what I want also. But the way it progressed made it harder / incompatible. Please, see #22 and if you're available you can help us figure out a way to make current types work with the extraction to propose a merge.