Fix createImportSpecifier with typescript 4.5+ #7426
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
↪️ 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