Added "type" entry for package exports #759
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.
Conventions
Issue: #757
Overview
When
moduleResolutionis set toNodeNextwithin atsconfig.json, it seemingly ignores the legacytypesfield completely, despiteindex.d.tsactually being correct in this case. I think it has to do with import specificity, but I can't be certain. The docs say that it looks for a co-located file (effector.mjs->effector.mjs.d.ts), but it definitely does not work that way, or the file output works in a way that doesn't allow Typescript to resolve the types.Whatever the problem, I'm not an active contributor to Effector and want to make minimally intrusive changes.
Changes
.jsand.cjs, the exports were updated to have at least atypes,require, anddefaultentry..mjsentries, the exports were updated to have atypes,import, anddefaultentry.umdentries, the exports were updated to have atypes, anddefault..d.tsare left unchangedDemo
Please check this link on branch
fix-demo. Runnpm run demoto prep the repo (Node V16.16.0+ yarn pre-req).The demo works by using this repo as a git submodule, and file-importing the
npm/{package}paths.Paths imported:
effectoreffector-reacteffector-solideffector-vueeffector-solidforestModifying
src/index.ts, and using Intellisense for each of the imports in that file, will demonstrate that the types do work. If you would like to contrast this with the broken version, checkout themasterbranch and try running thenpm run buildcommand. Thetscoutput will complain that it cannot find the types, and Intellisense will also detect nothing.Risks + Notes
typesentry was filled-in by referencing thenode_modulesof a new install, and using those specific files as thetypesvalue.Links
This link is the Typescript manual's overview for the type exports