-
-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Environment
ESLint version: HEAD
@eslint/json version: HEAD
Node version: 20.19.3
npm version: 10.9.2
Operating System: Windows 11
What problem do you want to solve?
Hi,
I'm raising this issue based on eslint/markdown#453, eslint/markdown#367 (comment), and eslint/markdown#367 (comment).
cc. @JoshuaKGoldberg
Currently, the JSON, CSS, and Markdown plugins export their types defined in types.ts
from the /types
entry point.
For example:
-
JSON:
@eslint/json/types
Lines 20 to 27 in bc2b317
"./types": { "require": { "types": "./dist/cjs/types.cts" }, "import": { "types": "./dist/esm/types.d.ts" } } -
CSS:
@eslint/css/types
-
Markdown:
@eslint/markdown/types
As mentioned in eslint/markdown#453, eslint/markdown#367 (comment), and also from my own experience, exporting types from a /types
entry point is a fairly uncommon pattern in TypeScript.
With this proposal, I'd like to suggest exporting types from the main entry point instead (i.e., @eslint/json
, @eslint/css
, and @eslint/markdown
), rather than from @eslint/json/types
, @eslint/css/types
, and @eslint/markdown/types
.
What do you think is the correct solution?
There are two possible approaches, depending on whether the build script uses bundling:
-
If bundling is used:
Adding
export * from "types.ts"
to thebanner
section inrollup.config.js
worked well and was the simplest way to achieve this proposal in my tests.Line 14 in bc2b317
banner: '// @ts-self-types="./index.d.ts"', -
If bundling is not used:
The following approach was the cleanest solution I found.
I've taken another shot at this and wanted to share a different approach.
Here's what I did:
- First, I created an empty
types.js
file atsrc/types.js
:
export default {};
- Then, I added
export * from "./types.js";
to the end ofindex.js
:
// ... export default plugin; export { MarkdownSourceCode }; + export * from "./types.js";
This approach seems to work well, since it allows all types from
src/types.ts
to be imported directly from the@eslint/markdown
package, rather than from@eslint/markdown/types
. - First, I created an empty
Participation
- I am willing to submit a pull request for this change.
Additional comments
This proposal applies to all packages that export their types from types.ts
using the @eslint/package-name/types
entry point.
So far, I've only reviewed the JSON, CSS, and Markdown plugins, but I plan to look into the other packages as I continue.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status