joi-extract-type
joi-extract-type copied to clipboard
Move joi-extract-type into Joi's definitely typed file
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
- joi-extract-type has direct access to all the types because it's now inside the namespace.
- joi-extract-type stays in sync with the joi definitions
- All users are able to get Types from their own schemas without another install
Disadvantages
- joi DefinitelyTyped costs more to maintain.
- Extends DefinitelyTyped beyond its strict purpose.
- @TCMiranda might want to keep this as a separate repo for reasons I haven't thought of...?
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
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.
My main concern is the performance of these deep complex generics. Can we have some benchmark with and without these typings and huge schemas?
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.
DT provides detailed statistics on every build about performance and warns about significant regressions.
What an awesome tool :open_mouth: Ok lets prepare a PR and see the impact. Thanks for this feedback.
@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?
}
}
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.)
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.