-
Notifications
You must be signed in to change notification settings - Fork 216
Closed
Description
While working on my previous PR, I delved into the TypeScript packages setup in this repository. Here's my understanding, along with some issues I've found and a suggestion for improvement.
I'm not fully aware of the reasoning behind the current setup, so please correct me if I'm wrong or if I'm missing something.
Current package setup
- Pure ESM package.
exportsfield points to compiled JS (.js) files.typesortypesVersionsfield points to source TS (.ts) files.- Does not generate DTS (TS type declaration,
.d.ts) files. moduleResolutionintsconfig.jsonis set tonode, an alias ofnode10.
This setup seems designed to provide a good developer experience within this repository. Developers/tsc directly refer to the TS files of dependent packages, while Node.js or bundlers use the JS files.
Issues with this setup for MUD packages users
- Users need to include the
@types/*dependencies, which are MUD packages' dev dependencies, in their projects to pass theirtsc, even if they do not directly use these dependencies. This is because the packages expose TS files instead of DTS files, leading to projects'tsctreating them as regular in-project TS files. This setup may also increase thetsctime of the projects. - Users must use specific configs in their
tsconfig.json, particularlymoduleResolution: node10. The recommended modern settings,bundlerornode16, are not usable because these settings rely onexportsfields rather thantype/typesVersionsfields for finding types, leading to errors due to missing type files.
Suggestion for improvement
The goal is to:
- Maintain the current developer experience in this repository.
- Avoid affecting existing (
moduleResolution: node10) users. - Resolve the
@types/*dependencies issue. - Allow users to opt for
bundlerornode16in their projects.
Steps to improve:
- Generate DTS files (set
dts: trueintsup.config.ts)- This would enable users to use
bundlerornode16, which find their corresponding DTS files based onexports. These users wouldn't need to have the@types/*. - No impact on developers and
node10users, asnode10does not recognizeexports. - The potential downside is increased build time for DTS generation.
- This would enable users to use
- Remove the
@types/*necessity fornode10users (Optional)- This can be achieved by overriding
types/typesVersionsfields to point to DTS instead of TS on packing, using pnpm'spublishConfigfeature. - No impact on developers since the only change is the addition of
publishConfigfields in packages'package.json.
- This can be achieved by overriding
- Switch to
bundlerornode16fromnode10in this repository's packages if desired (Optional)- The packages'
package.jsonshould haveexportsfields pointing to TS files andpublishConfig.exportsfields pointing to JS files.
- The packages'
Note
- These changes have not been tested yet. I wanted to confirm my understanding of the current setup and know the desired future direction. (It seems like step 1 is working without major issues in my local
/templatesproject withbundlerandnode16.) - Even when using MUD externally with a JS + DTS setting, I believe it's still possible to maintain the "go to TS definition" experience for users development environments by utilizing
tsc --declarationMap.
Metadata
Metadata
Assignees
Labels
No labels