Closed isaachinman closed 4 years ago
Probably not, no. I add all the TypeScript overhead to make working with celebrate
easier and provide a friendly developer experience in IDEs that support it; but @types/hapi__joi
is not required for celebrate
to run and I'd like to only add things to the dependencies that are required for the code to run.
Well, you're expecting users to use the Joi
export, so I'd expect types alongside that.
To put it another way: type annotations in general are not required for celebrate
to run, but every single TS project who installs celebrate
will also have to track things down and eventually install @types/hapi__joi
.
This would be a different story if @hapi/joi
was a peerDependency
and you expected it to be managed in user land. But you're pulling it in here as a regular dep and re-exporting it to users.
Hey @isaachinman it looks @types/hapi__joi
is installed as a devDependency here. I am curious why that doesn't address the issue?
@amitkirdatt devDependencies
are exactly that... They are not installed during prod installs.
Can you talk a bit about what the usecase is for using it in prod?
@amitkirdatt By "prod", we mean when the package is installed.
From this line in the type declaration file, it's clear that at least the person who wrote that line agreed that celebrate should provide the types for Joi as well as its functionality.
However, since @types/hapi__joi
is in the devDependencies, the Joi types imported in the type declaration file aren't present in the final bundled package.
Since celebrate bothers having to have a type declaration file, it makes sense that it would actually provide all the types for the API it exposes.
@arb that being said, if you can't be swayed to add it to the dependencies, it would be good to at least add a line in the README on how to install those typings, specifying the appropriate version.
@isaachinman So I'm reviewing this again and I'm still a bit confused. There are a bunch of ways to get npm or yarn to install dev deps if they are not installed by default. This varies depending on the version of npm or yarn you're using, but it's well documented. I'm not clear the situation you are in when the type definition for Joi is causing your code not to function correctly. Can you expand on that?
As previously state, the type defs were added to improve developer experience (DX) only; not to make celebrate type sound in TypeScript. This is why i only include it as a dev dep; you only get the DX benefit when actively doing development . This is not a TypeScript module and the existence of definition files or not does not prevent the code from executing as expected in Node as the unit and integration tests demonstrate.
I guess my final question is - what exactly is wrong, in your opinion, about not including the type defs in the regular dependencies? Does it prevent something from working? Or is this an issue where we disagree about what is and what is not "required" for the code to work as expected?
@remyoudemans I'm always open to documentation PRs! But again, this really boils down to the version of npm or yarn being used and the specifics of those package managers and how you tell them to also install dev deps.
Also, since this has become the type def thread, I opened https://github.com/arb/celebrate/issues/181 if anyone is interested in contributing!
what exactly is wrong, in your opinion, about not including the type defs in the regular dependencies? Does it prevent something from working?
It's an easy enough inclusion that prevents every single TS user from having to track this issue down and figure out where to get types from. It is industry standard now for packages themselves to provide types on the stuff they export.
Ok, you've changed my mind. I'll take a PR for this change and will also close #181.
Opened #182 – @remyoudemans can you please review? I no longer use this package in any projects.
@arb Side note, not having a lockfile can break semver.
@isaachinman Looks good to me!
Hi there. Would you consider installing
@types/hapi__joi
by default, to support TypeScript users? Took me a few minutes to track the types down. If you just installcelebrate
and attempt to use theJoi
export, it will be typed asany
until you install@types/hapi__joi
. The@types/hapi__joi
package should be a dependency ofcelebrate
.Happy to submit a PR.