TypeScript compatibility improvement #3651
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.
This PR reverts 1f484a2 to improve the compatibility with TypeScript by moving from
exports
.TypeScript 4.7 supported
exports
but it requiresmoduleResolution
set toNode16
. This leads to some side effects like relative imports have to include the extename (import('../a.js')
instead ofimport('../a')
), and most importantlyNode16
is not designed to be used together with bundlers in browser environments, as its name suggests and it brings some Node.js-specific requirements and behaviors.TypeScript 4.9 may provide some
moduleResolution
modes that can supportexports
without introducing any Node.js-specific behaviors: microsoft/TypeScript#50152. However, at best it will release at the end of this year so this is not something we can rely on now.The con of this PR is the TS outputs can clutter the dev filetree but it can be resolved with an additional build step (set the output path to
/dist
and when publish runnpm publish ./dist
) or a script to delete all outputs (seems the only case we build the TS is before publishing). Either of the workaround can be addressed in a separate PR/ticket.