Socket
Socket
Sign inDemoInstall

eslint-import-resolver-typescript

Package Overview
Dependencies
192
Maintainers
3
Versions
43
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eslint-import-resolver-typescript

TypeScript .ts .tsx module resolver for `eslint-plugin-import`.


Version published
Weekly downloads
6.3M
decreased by-20.96%
Maintainers
3
Install size
648 kB
Created
Weekly downloads
 

Package description

What is eslint-import-resolver-typescript?

The eslint-import-resolver-typescript package is a plugin for ESLint that helps in resolving import paths for TypeScript files. It allows ESLint to understand TypeScript syntax and resolve paths according to the TypeScript compiler options. This is particularly useful when using features like path aliases and custom module directories in TypeScript projects.

What are eslint-import-resolver-typescript's main functionalities?

Resolving TypeScript Path Aliases

This feature allows the resolver to use TypeScript's path aliases defined in tsconfig.json to resolve modules, which helps ESLint to understand custom path mappings.

module.exports = {
  settings: {
    'import/resolver': {
      typescript: {
        // use <root>/tsconfig.json
        project: '.'
      }
    }
  }
};

Support for Multiple tsconfig Files

The resolver can be configured to use multiple tsconfig.json files, which is useful in monorepos or projects with multiple TypeScript configurations.

module.exports = {
  settings: {
    'import/resolver': {
      typescript: {
        // a list of tsconfig.json to use
        project: ['tsconfig.json', 'packages/*/tsconfig.json']
      }
    }
  }
};

Ignoring TypeScript Errors

This feature allows the resolver to ignore TypeScript errors when resolving paths. It is useful when you want ESLint to focus on import/export issues without being blocked by TypeScript compilation errors.

module.exports = {
  settings: {
    'import/resolver': {
      typescript: {
        // ignore TypeScript errors
        alwaysTryTypes: true
      }
    }
  }
};

Other packages similar to eslint-import-resolver-typescript

Changelog

Source

2.4.0 (2021-02-16)

Features

  • remove any querystring from imports (#67) (82ef357)

Bug Fixes

  • remove .tsbuildinfo and d.ts.map files from package (#57) (15f2849)
  • remove redundant condition (#69) (ba62e65)

Readme

Source

eslint-import-resolver-typescript

GitHub Actions type-coverage npm GitHub Release

David Peer David David Dev

Conventional Commits JavaScript Style Guide Code Style: Prettier codechecks.io

This plugin adds TypeScript support to eslint-plugin-import.

This means you can:

  • import/require files with extension .ts/.tsx!
  • Use paths defined in tsconfig.json.
  • Prefer resolve @types/* definitions over plain .js.
  • Multiple tsconfigs support just like normal.

TOC

Notice

After version 2.0.0, .d.ts will take higher priority then normal .js files on resolving node_modules packages in favor of @types/* definitions.

If you're facing some problems on rules import/default or import/named from eslint-plugin-import, do not post any issue here, because they are just working exactly as expected on our sides, take https://github.com/benmosher/eslint-plugin-import/issues/1525 as reference or post a new issue to eslint-plugin-import instead.

Installation

# npm
npm i -D eslint-plugin-import @typescript-eslint/parser eslint-import-resolver-typescript

# yarn
yarn add -D eslint-plugin-import @typescript-eslint/parser eslint-import-resolver-typescript

Configuration

Add the following to your .eslintrc config:

{
  "plugins": ["import"],
  "rules": {
    // turn on errors for missing imports
    "import/no-unresolved": "error"
  },
  "settings": {
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
      "typescript": {
        "alwaysTryTypes": true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`

        // Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default

        // use <root>/path/to/folder/tsconfig.json
        "project": "path/to/folder",

        // Multiple tsconfigs (Useful for monorepos)

        // use a glob pattern
        "project": "packages/*/tsconfig.json",

        // use an array
        "project": [
          "packages/module-a/tsconfig.json",
          "packages/module-b/tsconfig.json"
        ],

        // use an array of glob patterns
        "project": [
          "packages/*/tsconfig.json",
          "other-packages/*/tsconfig.json"
        ]
      }
    }
  }
}

Contributing

  • Make sure your change is covered by a test import.
  • Make sure that yarn test passes without a failure.
  • Make sure that yarn lint passes without conflicts.
  • Make sure your code changes match our type-coverage settings: yarn type-coverage.

We have GitHub Actions which will run the above commands on your PRs.

If either fails, we won't be able to merge your PR until it's fixed.

Keywords

FAQs

Last updated on 16 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc