-
Notifications
You must be signed in to change notification settings - Fork 508
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
change: use peerDeps for typescript, tslib #985
Conversation
This comment has been minimized.
This comment has been minimized.
why not just bump up typescript to v4 #926 ?The key is tsdx shouldn't help user to make a choice which version user should use. In other words, tsdx shouldn't provide typescript and tslib for better compatibility(eg, practice in next.js). use resolution field in package.json ? just like #926 (comment)It's not an elgant solution, and more mental burden. The important thing is that only works with yarn, not npm. |
@lbwa I appreciate the detailed write-up, but this is a known issue and not as simple as you suggest. For changes as ranging as this, I would definitely recommend making an issue first before jumping into a PR. Compatibility is a huge issuePlease see #952 (comment) where I've previously answered the question as to why peerDeps aren't used (history, "all-in-one") and as to why peerDeps are not necessarily an optimal solution. In summary, lots of deps and TSDX itself can and do break easily and often due to TS changes, and TS does not follow SemVer and has a breaking change every minor (this would most likely result in more issues, not less). It is not quite like the React example you point out in Next -- React is one of the most, if not the most, stable package out there; even React's breaking changes tend to not break much and be straightforward to upgrade through if necessary. Compatibility is also the most common type of issue in TSDX by a fairly wide margin, so we generally do not want to make that scenario worse. That is why several of my RFCs and pending changes try to break out TSDX into more components that can be separately updated, better overrided, and even opted-out. But we're not there yet, so this kind of change is particularly early. Even if I wanted to merge this, TSDX itself is not ready or compatible with it. This change is also very breaking and itself is not compatible with all of the other dependencies TSDX has that rely on TypeScript and rely on a specific version. #926 (comment) shows some of that particular issue -- it does not solely bump TS. FutureAs such, at this time I'll be closing this PR as won't fix. Maybe in the future TSDX will be ready for such a change, but it is not at this time.
Yes, that's meant to be a workaround and is listed as such, not a permanent solution.
|
Ok. Thanks for your response and contributions. Your explanation is very helpful. |
See my other comment where I explain how it works fine with NPM. edit: Just realised you do need a certain recent version of NPM, and maybe that's why it didn't work for you on NPM. |
Shortly, typescript and tslib should always be a member of
peerDependencies
, rather thandependencies
. Otherwise, tsdx user never use their own tslib and typescript due to nodejs module resolution rules.reproduce
src/index.ts
:yarn build # semantic error TS2304: Cannot find name 'Lowercase'.
But Lowercase actually is typescript
Intrinsic String Manipulation Types
in v4why
Everything go back to normal when I delete typescript dir in
<PROJECT_ROOT>/node_modules/tsdx/node_modules/typescript
. I wrote some code only supported by typescript v4, but tsdx only require typescript v3x.tsdx always require tsdx's typescript and tslib, rather than user's own version due to nodejs module resolution rules.
This code always requires typescript from tsdx's dependencies, rather than project's dependencies, that code typescript version never works!!
conclusion
typescript should always be a member of peerDependencies. tslib too.
solution
move typescript, tslib into peerDependencies field
throw importation error when typescript isn't installed, but tslib only throws a warning.
for tsdx template user
Nothing needs to be done (because tsdx template will install typescript and tslib automatically)
for standalone user (without tsdx template)