question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"import type" from TypeScript 3.8 not recognized

See original GitHub issue

After upgrading to TypeScript 3.8.2 I also use the new “import type” feature https://www.typescriptlang.org/docs/handbook/modules.html#importing-types. Now I’m getting a warning from import/no-duplicates.

My affected code is e.g.:

import type { Options } from 'express-rate-limit';
import rateLimit from 'express-rate-limit';

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

14reactions
xiaoxiangmoecommented, Mar 11, 2020

rule import/order also needs to consider import type and import

2reactions
kmui2commented, Mar 4, 2020

Seems TypeScript ESLint currently (v2.22.0) does not have support for TypeScript 3.8 yet (>=3.2.1 <3.8.0, https://github.com/typescript-eslint/typescript-eslint/issues/1436). Because of this, it’s not currently possible to write a test for the import type syntax. So I’m afraid we need to wait for the TypeScript 3.8 support for ESLint.

For future reference, here’s the test I was writing:

context('TypeScript', function() {
  getNonDefaultParsers().forEach((parser) => {
    const parserConfig = {
      parser: parser,
      settings: {
        'import/parsers': { [parser]: ['.ts'] },
        'import/resolver': { 'eslint-import-resolver-typescript': true },
      },
    }

    ruleTester.run('no-duplicates', rule, {
      valid: [
        // #1667: ignore duplicate if is a typescript type import
        test(
          {
            code: "import type { x } from './foo'; import y from './foo'",
            parser,
          },
          parserConfig,
        ),
      ],
      invalid: [],
    })
  })
})
    "@typescript-eslint/parser": "^2.22.0",
    "eslint-import-resolver-typescript": "^2.0.0",
    "typescript": "^3.8.3",

As of these TypeScript ESLint package versions, it will produce the error:

AssertionError [ERR_ASSERTION] [ERR_ASSERTION]: A fatal parsing error occurred in autofix: Parsing error: '{' expected.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 3.8
import type only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there's no remnant of...
Read more >
Support TypeScript 3.8 type-only imports/exports in resolve ...
Hi, using PHPStorm 2021.2.2, I do not get the auto import type feature despite having importsNotUsedAsValues set to 'error' but it only seems...
Read more >
Do I need to use the "import type" feature of TypeScript 3.8 if ...
Long answer: As TypeScript 3.8 release notes say: import type only imports declarations to be used for type annotations and declarations. It ...
Read more >
Announcing TypeScript 3.8 RC - Microsoft Developer Blogs
As a solution in TypeScript 3.8, we've added a new syntax for type-only imports and exports. import type { SomeThing } ...
Read more >
ts-node - npm
TypeScript icon, indicating that this package has built-in type ... This error is thrown by node when a module has an unrecognized file ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found