eslint-plugin-typeorm-typescript is an ESLint plugin designed to ensure type consistency between TypeORM entity definitions and their corresponding TypeScript types. It identifies discrepancies in primitive types (e.g., `varchar` vs. `number`), handles driver-specific type parsing (notably `bigint` and `decimal` which are often strings), and enforces correct nullability for columns and relations. The current stable version is `0.5.3`. The project appears to have an active release cadence, frequently introducing new rules and updating support for newer ESLint and TypeScript-ESLint versions. A key differentiator is its ability to catch subtle TypeORM-specific type mismatches that static TypeScript analysis alone cannot, particularly around default nullability behaviors and specific database type mappings. It supports both legacy and modern ESLint flat configurations, providing flexibility for different project setups.
npm install eslint-plugin-typeorm-typescriptVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up `eslint-plugin-typeorm-typescript` with ESLint flat configuration in a TypeScript project, including recommended rules and custom options for specific rules.
Upgrade your Node.js environment to version 20 or higher to maintain compatibility and receive updates.
Review TypeORM column definitions and their corresponding TypeScript types for `bigint` and `decimal`. For most drivers, these are now parsed as `string` in TypeScript (e.g., `string` instead of `number` for `bigint`). Adjust your TypeScript types accordingly.
Migrate your ESLint configuration to the new flat config format (e.g., `eslint.config.mjs`). Use `typeormTypescriptRecommended` for a quick setup, or manually configure the plugin as detailed in the 'Flat configuration' section of the README. Ensure your Node.js environment supports ESM if using `import` statements.
Utilize the `typeorm-typescript/enforce-relation-types` rule. Additionally, consider enabling the `typeorm-typescript/enforce-consistent-nullability` rule (introduced in v0.3.0) with `"specifyNullable": "always"` to enforce explicit nullability declarations for all columns and relations.
Ensure `eslint-plugin-typeorm-typescript` is installed as a dev dependency (`npm install -D eslint-plugin-typeorm-typescript`) and correctly referenced in your `.eslintrc.json` (`"plugins": ["typeorm-typescript"]`) or `eslint.config.mjs` (`typeormTypescriptPlugin` or `typeormTypescriptRecommended`).
If using an ESLint flat config file (e.g., `eslint.config.mjs`), ensure your environment (e.g., Node.js 20+) supports ESM. If sticking with CommonJS for legacy `.eslintrc.js` files, use `require()` statements instead of `import`.
When providing options for a rule, ensure they are passed as the second element of an array where the first element is the rule's severity level (e.g., `"error"`). The options themselves should be a valid JavaScript object: `["error", { "driver": "sqlite" }]`.