This plugin adds TypeScript
support to eslint-plugin-import
(Or maybe you want to try eslint-plugin-i
for faster speed)
This means you can:
import
/require
files with extension.cts
/.mts
/.ts
/.tsx
/.d.cts
/.d.mts
/.d.ts
- Use
paths
defined intsconfig.json
- Prefer resolving
@types/*
definitions over plain.js
/.jsx
- Multiple tsconfigs support just like normal
imports/exports
fields support inpackage.json
- Notice
- Installation
- Configuration
- Options from
enhanced-resolve
- Contributing
- Sponsors
- Backers
- Changelog
- License
After version 2.0.0, .d.ts
will take higher priority then normal .js
/.jsx
files on resolving node_modules
packages in favor of @types/*
definitions or its own definition.
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 import-js/eslint-plugin-import#1525 as reference or post a new issue to eslint-plugin-import
instead.
# npm
npm i -D eslint-plugin-import eslint-import-resolver-typescript
# pnpm
pnpm i -D eslint-plugin-import eslint-import-resolver-typescript
# yarn
yarn add -D eslint-plugin-import eslint-import-resolver-typescript
Add the following to your .eslintrc
config:
Options from enhanced-resolve
Default:
[
"types",
"import",
// APF: https://angular.io/guide/angular-package-format
"esm2020",
"es2020",
"es2015",
"require",
"node",
"node-addons",
"browser",
"default"
]
Default:
[
// `.mts`, `.cts`, `.d.mts`, `.d.cts`, `.mjs`, `.cjs` are not included because `.cjs` and `.mjs` must be used explicitly
".ts",
".tsx",
".d.ts",
".js",
".jsx",
".json",
".node"
]
Default:
{
".js": [
".ts",
// `.tsx` can also be compiled as `.js`
".tsx",
".d.ts",
".js"
],
".jsx": [".tsx", ".d.ts", ".jsx"],
".cjs": [".cts", ".d.cts", ".cjs"],
".mjs": [".mts", ".d.mts", ".mjs"]
}
Default:
[
"types",
"typings",
// APF: https://angular.io/guide/angular-package-format
"fesm2020",
"fesm2015",
"esm2020",
"es2020",
"module",
"jsnext:main",
"main"
]
You can pass through other options of enhanced-resolve
directly
You can reuse defaultConditionNames
, defaultExtensions
, defaultExtensionAlias
and defaultMainFields
by require/import
them directly
- 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.
1stG | RxTS | UnTS |
---|---|---|
1stG | RxTS | UnTS |
---|---|---|
Detailed changes for each release are documented in CHANGELOG.md.