-
Notifications
You must be signed in to change notification settings - Fork 202
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
Current TypeScript packages setup and improvement suggestion #2051
Comments
I don't think there was a ton of thought given to the current set up and likely is a result of copy+paste and iterative evolution. Maximum compatibility would be great with a preference towards user experience both for us building inside MUD monorepo and for users consuming the packages.
Would love for us to figure this out. My biggest beef with libraries using |
Step 1 has been completed in #2084. Please note that this PR does not affect users with |
I agree! Most libraries use a JS + DTS setup, but some libraries like viem include type declaration maps ( |
As a follow-up to step 1, we should have CI to ensure that the DTS setup works in user environments. |
Reflecting on #2036 (comment), here are the remaining tasks:
|
most of these have been done in #2828 |
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
exports
field points to compiled JS (.js
) files.types
ortypesVersions
field points to source TS (.ts
) files..d.ts
) files.moduleResolution
intsconfig.json
is 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
@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'tsc
treating them as regular in-project TS files. This setup may also increase thetsc
time of the projects.tsconfig.json
, particularlymoduleResolution: node10
. The recommended modern settings,bundler
ornode16
, are not usable because these settings rely onexports
fields rather thantype
/typesVersions
fields for finding types, leading to errors due to missing type files.Suggestion for improvement
The goal is to:
moduleResolution: node10
) users.@types/*
dependencies issue.bundler
ornode16
in their projects.Steps to improve:
dts: true
intsup.config.ts
)bundler
ornode16
, which find their corresponding DTS files based onexports
. These users wouldn't need to have the@types/*
.node10
users, asnode10
does not recognizeexports
.@types/*
necessity fornode10
users (Optional)types
/typesVersions
fields to point to DTS instead of TS on packing, using pnpm'spublishConfig
feature.publishConfig
fields in packages'package.json
.bundler
ornode16
fromnode10
in this repository's packages if desired (Optional)package.json
should haveexports
fields pointing to TS files andpublishConfig.exports
fields pointing to JS files.Note
/templates
project withbundler
andnode16
.)tsc --declarationMap
.The text was updated successfully, but these errors were encountered: