eslint-type-tracer
raw JSON → 0.5.2 verified Sat Apr 25 auth: no javascript
A utility for inferring runtime types of expression nodes within ESLint rules, enabling type-aware linting without a full TypeScript type checker. Version 0.5.2 is the latest stable release with support for Temporal, Math.sumPrecise(), well-known symbols, and improved type definitions. It is published under MIT license and maintained by ota-meshi. Key differentiators: lightweight, no external runtime dependencies, limited to single-file analysis (no cross-module inference), and exports ESM via .mjs extension. Designed for ESLint v8.57+, Node.js >=18. Typical use cases include validating arrays, strings, numbers, and other built-in types inside ESLint rule implementations.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported. ↓
cause Since v0.5.1, the package exports ES modules (.mjs) and CommonJS require() is not natively supported in older Node versions.
fix
Use dynamic import: const { buildTypeTracer } = await import('eslint-type-tracer'); or use ESM in your project.
error Cannot find module 'eslint-type-tracer' or its corresponding type declarations. ↓
cause TypeScript cannot find types if the package is not installed or if the import path is wrong.
fix
Ensure eslint-type-tracer is installed and that you are using the correct import: import { buildTypeTracer } from 'eslint-type-tracer'.
Warnings
breaking In v0.5.0, support for Temporal was added, which may cause breakage if your code expects previous behavior with Date-like types now being inferred as Temporal types. ↓
fix Update to v0.5.2 or later where Temporal definitions were improved.
breaking In v0.2.0, the API was redesigned. The previous default export or function signatures are removed. ↓
fix Migrate to v0.2.0+ using buildTypeTracer and buildTypeChecker.
deprecated The package is ESM-first starting v0.5.1. CommonJS require may still work but is not officially supported and may break in future versions. ↓
fix Switch to ESM imports ('import { ... } from "eslint-type-tracer"') or use dynamic import.
gotcha Type inference is limited to the current file only. Cross-module types cannot be inferred. ↓
fix Do not rely on the tool for cross-module inference; consider using TypeScript's type checker if needed.
Install
npm install eslint-type-tracer yarn add eslint-type-tracer pnpm add eslint-type-tracer Imports
- buildTypeTracer wrong
const { buildTypeTracer } = require('eslint-type-tracer')correctimport { buildTypeTracer } from 'eslint-type-tracer' - buildTypeChecker wrong
import buildTypeChecker from 'eslint-type-tracer'correctimport { buildTypeChecker } from 'eslint-type-tracer' - TypeName
import type { TypeName } from 'eslint-type-tracer'
Quickstart
import { buildTypeTracer } from 'eslint-type-tracer';
import type { Rule } from 'eslint';
const myRule: Rule.RuleModule = {
create(context) {
const typeTrace = buildTypeTracer(context.sourceCode);
return {
CallExpression(node) {
const callee = node.callee;
if (callee.type === 'MemberExpression') {
const objectTypeNames = typeTrace(callee.object);
if (objectTypeNames.includes('Array')) {
context.report({ node, message: 'Array method called.' });
}
}
}
};
}
};
export default myRule;