-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make optional peer dependencies actually optional #405
Comments
Hi @octogonz, I'm still on vacation until July 17, so please excuse my very short answer. Solution number 1 has been on my todo list for quite some time for the next refactoring with several breaking changes, which I haven't gotten to yet due to time constraints. I haven't thought about solution number 2 at all and it seems very interesting to me because it would be implementable with relatively manageable effort and with few (if not completely no) breaking changes. I have to look at that after the vacation in again, thank you for this idea. And about No. 3 I think we do not really need to talk big I think 😂 |
Thanks for the reply. Have a good vacation! |
# [3.5.0-develop.1](v3.4.4-develop.8...v3.5.0-develop.1) (2022-07-25) ### Features * Replace external types with stub types ([56cffc7](56cffc7)), closes [#405](#405)
🎉 This issue has been resolved in version 3.5.0-develop.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Hi @octogonz, sorry it took so long now. I have implemented suggestion no. 2 and published it in version |
I tested Thank you for making this fix! |
# [3.5.0](v3.4.3...v3.5.0) (2022-07-27) ### Features * Replace external types with stub types ([56cffc7](56cffc7)), closes [#405](#405)
🎉 This issue has been resolved in version 3.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
And also remove the now really optional dependencies. See sebbo2002/ical-generator#405 for more details.
And also remove the now really optional dependencies. See sebbo2002/ical-generator#405 for more details.
For TypeScript users, the above advice defeats the purpose of declaring the vendor packages as "optional." This is unfortunate, since people who use TypeScript tend to be the audience who cares most about rigorous management of dependencies.😉
Is there a better solution? Here's some ideas:
Idea 1: "Opt-in" by decoupling the API
The ideal would be to redesign the API so that the vendor integrations are opt-in via specific imports, rather than being tightly coupled. (This is the same idea behind Day.js plugins.)
For example, instead of this:
src/calendar.ts
We might do something like this:
src/calendar.ts
If someone has
moment
, one approach would be to type-check by importing an adapter:example-consumer.ts
This is just one possibility. There are many ways to design an API that cleanly separates its dependencies. Doing so might also eliminate the awkward Webpack workaround that arose because one small feature entangles the entire bundle with Node.js
fs
.Idea 2: Replace the dependencies with stub types
The
ical-generator
API is very disciplined about accepting vendor objects as inputs, but never exposing them as outputs. Thus, the type declarations don't actually provide operations, they merely check for an incorrect input. Since TypeScript uses structural typing instead of nominal typing, theical-generator
package could provide its own types:(Compare with the real moment/ts3.1-typings/moment.d.ts.)
Idea 3: "Opt-out" via a stub import
A final possibility would be to provide a stub that consumers can import if they do want type checking for
ical-generator
but don't care about any vendor integrations.ical-generator/dist/disable-integrations.d.ts
Then the consumer can avoid installing irrelevant peer dependencies like this:
example-consumer.ts
Idea 3 is how I worked around the problem in my own project, but it seems like the most clumsy of these ideas.
The text was updated successfully, but these errors were encountered: