TypeScript resolver plugin for eslint-plugin-import that enables TypeScript module resolution with path mapping and @types/* support
npx @tessl/cli install tessl/npm-eslint-import-resolver-typescript@4.4.0ESLint Import Resolver TypeScript is a resolver plugin for eslint-plugin-import and eslint-plugin-import-x that adds comprehensive TypeScript support to ESLint import rules. It enables importing TypeScript files with various extensions, supports TypeScript path mapping from tsconfig.json, prefers @types/* definitions over plain JavaScript files, handles multiple TypeScript configurations, and supports modern package.json imports/exports fields.
npm install -D eslint-plugin-import-x eslint-import-resolver-typescriptimport {
resolve,
createTypeScriptImportResolver,
normalizeOptions,
mangleScopedPackage,
removeQuerystring,
sortProjectsByAffinity,
tryFile,
toGlobPath,
toNativePath,
defaultConfigFile,
log
} from "eslint-import-resolver-typescript";For CommonJS:
const {
resolve,
createTypeScriptImportResolver,
normalizeOptions,
mangleScopedPackage,
removeQuerystring,
sortProjectsByAffinity,
tryFile,
toGlobPath,
toNativePath,
defaultConfigFile,
log
} = require("eslint-import-resolver-typescript");The resolver is typically configured in ESLint configuration files rather than used directly:
// eslint.config.js
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
export default [
{
settings: {
'import-x/resolver-next': [
createTypeScriptImportResolver({
alwaysTryTypes: true,
project: './tsconfig.json',
}),
],
},
},
]For legacy .eslintrc configuration:
{
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": "./tsconfig.json"
}
}
}
}The resolver is built around several key components:
resolve() function that performs TypeScript-aware module resolutioncreateTypeScriptImportResolver() factory for creating ESLint-compatible resolver instancesPrimary module resolution functionality that resolves TypeScript modules using configurable options and TypeScript project settings.
function resolve(
source: string,
file: string,
options?: TypeScriptResolverOptions | null,
resolver?: ResolverFactory | null
): ResolvedResult;
interface ResolvedResult {
found: boolean;
path?: string | null;
}Factory function for creating ESLint-compatible resolver instances with TypeScript support and automatic configuration detection.
function createTypeScriptImportResolver(
options?: TypeScriptResolverOptions | null
): {
interfaceVersion: 3;
name: string;
resolve(source: string, file: string): ResolvedResult;
};Option normalization and TypeScript project configuration management for handling various project structures and settings.
function normalizeOptions(
options?: TypeScriptResolverOptions | null,
cwd?: string
): TypeScriptResolverOptions;
interface TypeScriptResolverOptions extends NapiResolveOptions {
project?: string[] | string;
alwaysTryTypes?: boolean;
bun?: boolean;
noWarnOnMultipleProjects?: boolean;
}Helper functions for path manipulation, package name mangling, project affinity sorting, and debug logging.
function mangleScopedPackage(moduleName: string): string;
function removeQuerystring(id: string): string;
function sortProjectsByAffinity(projects: string[], file: string): string[];
function tryFile(
filename?: string[] | string,
includeDir?: boolean,
base?: string
): string;
function toGlobPath(pathname: string): string;
function toNativePath(pathname: string): string;
declare let defaultConfigFile: string;
declare const log: (message?: any, ...optionalParams: any[]) => void;interface NapiResolveOptions {
/** Condition names for package.json exports resolution */
conditionNames?: string[];
/** File extensions to resolve */
extensions?: string[];
/** Extension aliases for TypeScript compilation */
extensionAlias?: Record<string, string[]>;
/** Package.json main fields priority */
mainFields?: string[];
/** Module aliases configuration */
alias?: Record<string, string | string[]>;
/** Package.json fields containing alias information */
aliasFields?: string[][];
/** Names of description files (like package.json) */
descriptionFiles?: string[];
/** Whether to enforce file extensions */
enforceExtension?: boolean;
/** Whether to resolve symlinks */
symlinks?: boolean;
/** TypeScript configuration options */
tsconfig?: {
configFile?: string;
references?: 'auto' | boolean;
};
}
interface TypeScriptResolverOptions extends NapiResolveOptions {
/** TypeScript project configuration paths */
project?: string[] | string;
/** Whether to always try to resolve @types packages (default: true) */
alwaysTryTypes?: boolean;
/** Whether Bun core modules should be accounted for */
bun?: boolean;
/** Suppress multiple projects warning */
noWarnOnMultipleProjects?: boolean;
}
interface ResolvedResult {
/** Whether the module was successfully resolved */
found: boolean;
/** Resolved file path, null for built-in modules */
path?: string | null;
}declare let defaultConfigFile: string;
declare const defaultConditionNames: string[];
declare const defaultExtensions: string[];
declare const defaultExtensionAlias: Record<string, string[]>;
declare const defaultMainFields: string[];
declare const JS_EXT_PATTERN: RegExp;
declare const IMPORT_RESOLVER_NAME: string;
declare const interfaceVersion: number;
declare const DEFAULT_TSCONFIG: string;
declare const DEFAULT_JSCONFIG: string;
declare const DEFAULT_CONFIGS: string[];
declare const DEFAULT_TRY_PATHS: string[];
declare const MATCH_ALL: string;
declare const DEFAULT_IGNORE: string;
declare const TSCONFIG_NOT_FOUND_REGEXP: RegExp;