Skip to content

ESLint Plugin: Ship type declarations for the public API - #82739

Open
USERSATOSHI wants to merge 5 commits into
WordPress:trunkfrom
USERSATOSHI:fix/eslint-plugin-type-definitions
Open

USERSATOSHI wants to merge 5 commits into
WordPress:trunkfrom
USERSATOSHI:fix/eslint-plugin-type-definitions

Conversation

@USERSATOSHI

Copy link
Copy Markdown
Contributor

What?

Closes #82494

Adds TypeScript type declarations to @wordpress/eslint-plugin, so it can be used from a type-checked eslint.config.ts without a declare module shim.

Why?

The package ships no declarations, so importing it in a typed flat config fails:

TS7016: Could not find a declaration file for module '@wordpress/eslint-plugin'.

With typescript-eslint strict rules on, the resulting any also triggers no-unsafe-member-access and no-unsafe-assignment in the config itself. Consumers currently work around it with an ambient module shim.

How?

Adds three declaration files under packages/eslint-plugin/types/:

  • shared.d.ts: the ConfigName and RuleName unions, PluginMeta and Rules, shared by both entry points.
  • index.d.ts: the main export, with configs typed as Record<ConfigName, Linter.Config[]>.
  • eslintrc.d.ts: the same for the deprecated /eslintrc export, using Linter.LegacyConfig.

Config and rule names are string literal unions, so only names the plugin actually exports are accepted. ESLint.Plugin was not reused directly because it types configs as Record<string, unknown>, which loses that precision. The plugin object is still assignable to ESLint.Plugin.

Also:

  • package.json: adds the types field, a types condition on both export subpaths, and types to files.
  • Drops the @types/eslint dev dependency. ESLint ships its own types since 9.10, and having both risks checking against the older DefinitelyTyped shapes. Only this package declared it.
  • tsconfig.json: adds the declarations to files and widens rootDir to . so they are type checked.
  • README: documents typed config usage.

Testing Instructions

  1. npm install
  2. npm run typecheck passes.
  3. npm run lint:js and npm run lint:pkg-json pass.

To check the consumer side:

  1. npm pack --workspace @wordpress/eslint-plugin

  2. Install the tarball in a scratch project with eslint@^10, typescript, jiti and typescript-eslint.

  3. Add an eslint.config.ts:

    import { defineConfig } from 'eslint/config';
    import wordpress from '@wordpress/eslint-plugin';
    
    export default defineConfig( {
    	extends: [ wordpress.configs.recommended ],
    } );
  4. tsc --noEmit reports TS7016 before this change and passes after.

  5. wordpress.configs[ 'not-a-config' ] and wordpress.rules[ 'not-a-rule' ] should be type errors.

  6. eslint . still works the same. No rule or config code changed.

Testing Instructions for Keyboard

N/A, no UI changes.

Screenshots or screencast

N/A, types only.

Use of AI Tools

Claude Code was used to draft the declaration files, the config wiring and this description. I reviewed everything manually and tested on latest version of eslint.

@github-actions github-actions Bot added the [Tool] ESLint plugin /packages/eslint-plugin label Sep 10, 2026
@github-actions

Copy link
Copy Markdown

🤖 PR meta 🤖

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@USERSATOSHI
USERSATOSHI marked this pull request as ready for review September 11, 2026 06:46
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: USERSATOSHI <tusharbharti@git.wordpress.org>
Co-authored-by: marekdedic <marekdedic@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Tool] ESLint plugin /packages/eslint-plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@wordpress/eslint-plugin: ship TypeScript type definitions for typed flat configs

1 participant