import-js/eslint-plugin-import

No errors for TypeScript `import` types

Open

#1,675 opened on Mar 3, 2020

 (7 comments) (0 reactions) (0 assignees)JavaScript (1,549 forks)batch import
enhancementhelp wantedtypescript

Repository metrics

Stars
 (5,940 stars)
PR merge metrics
 (Avg merge 138d 22h) (3 merged PRs in 30d)

Description

Docs on import types: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types

Reduced test case (all dependencies are latest):

// ./cypress/test.ts

// Expected error, got one
// Unexpected path "../app/helpers/api" imported in restricted zone
import Api from '../app/helpers/api';

// Expected error, but got none
type Api = typeof import('../app/helpers/api');
// .eslintrc.js
const config = {
  extends: ['plugin:import/typescript'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module',
  },
  plugins: ['import'],
  rules: {
    'import/no-restricted-paths': [
      2,
      {
        basePath: '.',
        zones: [
          {
            target: './cypress',
            from: './app',
          },
        ],
      },
    ],
  },
}

module.exports = config;

Contributor guide