Skip to content

Change Request: Export types from main entry point #130

@lumirlumir

Description

@lumirlumir

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:


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 the banner section in rollup.config.js worked well and was the simplest way to achieve this proposal in my tests.

    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 at src/types.js:
    export default {};
    • Then, I added export * from "./types.js"; to the end of index.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.

    image

    image

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

enhancementNew feature or request

Type

No type

Projects

Status

Blocked

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions