fix: Add types to package export map #569
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 is a possible fix for StoneCypher/fsl#1295.
As noted in that issue, TypeScript is unable to find the included jssm types in some configurations. Part of the problem is that there are no types in the export map, so this PR updates the export map to include
types
entries.I also created a rolled-up declaration for ESM and CJS using rollup-plugin-dts. This seems to work well in my testing and is the smallest fix I know of. I prototyped those changes and tested them on the repro project at https://github.com/tylerbutler/jssm-node16 and compilation worked as expected for both CJS and ESM.
Because jssm is using Rollup v2, I used an older release of rollup-plugin-dts since the most recent version requires Rollup 3.
Possible risks:
As it stands today without this change, TypeScript projects using more recent
moduleResolution
settings will fail to compile outright. With this change, those projects can compile and will see jssm types. However, there is a risk that rollup-plugin-dts produces invalid or flawed declaration files, or that there are further types-related issues that are uncovered by this change.That said, this change should be exceedingly safe in terms of runtime behavior, because all the changes are limited to the types-level only, and thus only affect compilation in TypeScript projects. The runtime jssm JS has not changed.