-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix createImportSpecifier with typescript 4.5+ #7426
Fix createImportSpecifier with typescript 4.5+ #7426
Conversation
|
.split('.') | ||
.map(num => parseInt(num, 10)); | ||
// The signature of createImportSpecifier had a breaking change in Typescript 4.5. | ||
// see: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#type-modifiers-on-import-names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wowwwwww... TS doesn't follow semver?? Maybe we should pin our dependency on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other side of that coin: #5978
Though that would break if Typescript implemented |
↪️ Pull Request
This fixes #7325 and possibly also #7400. The issue, as @benpigchu pointed out here, was that Typescript 4.5 added support for type modifiers on specific import names. For example, it is now valid to write:
Unfortunately, the way that the compiler API was changed to support this is not backward compatible :-(
Here's what the pre-4.5 API looked like:
And here's the new API (see PR):
Since there's no way that I know of to check a function's arity at runtime, I had to resort to a version check.
There were several other backward-incompatible changes in that PR (to
updateImportSpecifier
,createExportSpecifier
andupdateExportSpecifier
), and I verified that we don't use these APIs in parcel.💻 Examples
Without this change, when you have typescript 4.5+,
@parcel/transformer-typescript-types
will generate output like:instead of
This change ensures that we do the right thing.
🚨 Test instructions
Several of the existing unit tests will break if you upgrade to typescript 4.5+ and don't apply this change, so it didn't seem necessary to add new ones.
I manually verified that with this change, and typescript 4.2.4 (the old version in the repo), all the unit tests still pass. You can test it yourself by modifying
yarn.lock
to revert back to4.2.4
, runningyarn install
, thenyarn test:integration
.✔️ PR Todo