eslint-typegen
raw JSON → 2.3.1 verified Sat Apr 25 auth: no javascript
Generates TypeScript types from ESLint rule JSON schemas automatically, providing auto-completion and type-checking for rule options. Current stable version is 2.3.1, with an active release cadence. Key differentiators: leverages ESLint's flat config to generate types on the fly, uses json-schema-to-typescript-lite under the hood, and is ESM-only from v2.0.0. Eliminates manual type definitions for ESLint plugin options.
Common errors
error TypeError: Cannot read properties of undefined (reading 'rules') ↓
cause Typegen is called with a config array that is empty or missing rules.
fix
Ensure typegen() receives an array of valid flat config objects: typegen([...configs]).
error [ERR_REQUIRE_ESM] require() of ES Module from CommonJS ↓
cause Package is ESM-only since v2.0.0; CJS require() is not supported.
fix
Convert your script to ESM (use 'import') or use dynamic import: const typegen = (await import('eslint-typegen')).default.
error Cannot find module 'eslint-typegen/core' ↓
cause Using a version before v2.0.0 where 'eslint-typegen/core' subpath did not exist.
fix
Upgrade to v2.0.0+ or use import { pluginsToRulesDTS } from 'eslint-typegen' in older versions (check docs accordingly).
error ESLint error: Failed to load config 'eslint-typegen' in plugin ↓
cause Mistakenly trying to use eslint-typegen as an ESLint plugin instead of a config generator function.
fix
Use typegen as an exported function, not as a plugin. Remove from plugins array and wrap config: export default typegen([...]).
Warnings
breaking ESM-only since v2.0.0. CommonJS require() will throw an error. ↓
fix Convert to ESM (use 'import' syntax or dynamic import) or pin to v1.x if CJS is required.
deprecated The @types/eslint dependency was removed in v0.3.2; types are self-contained. ↓
fix Upgrade to v0.3.2+ to avoid needing @types/eslint separately.
gotcha Type generation only triggers on ESLint run; it does not happen at import time. ↓
fix Run ESLint at least once after configuration changes to regenerate eslint-typegen.d.ts.
gotcha If using @antfu/eslint-config, typegen types are already bundled; do not add separate eslint-typegen setup. ↓
fix Skip installing eslint-typegen if using @antfu/eslint-config; its types are pre-generated.
gotcha Peer dependency eslint ^9.0.0 || ^10.0.0; flat config required. ↓
fix Ensure project uses ESLint 9+ with flat config (eslint.config.js/mjs). Not compatible with legacy .eslintrc.
Install
npm install eslint-typegen yarn add eslint-typegen pnpm add eslint-typegen Imports
- typegen wrong
import { typegen } from 'eslint-typegen'correctimport typegen from 'eslint-typegen' - pluginsToRulesDTS wrong
import pluginsToRulesDTS from 'eslint-typegen'correctimport { pluginsToRulesDTS } from 'eslint-typegen/core' - pluginsToRulesDTS wrong
const pluginsToRulesDTS = require('eslint-typegen/core')correctconst { pluginsToRulesDTS } = await import('eslint-typegen/core')
Quickstart
// @ts-check
/// <reference path="./eslint-typegen.d.ts" />
import typegen from 'eslint-typegen'
export default typegen(
[
{
rules: {
'semi': ['error', 'always'],
},
},
]
)
// Run ESLint once to generate eslint-typegen.d.ts
// npx eslint .