eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

Request: option to let `no-duplicates` force type & normal imports to be de-duplicated

Open TiddoLangerak opened this issue 7 years ago • 7 comments

#225 asked to allow both type & normal imports to be allowed together, e.g.

import {someFunction} from '../src/foo';
import type {someType} from '../src/foo';

This was requested because according to the author there was no way to merge these together at that point in time.

However, currently flow does support merging these imports together:

import { someFunction, type someType } from '../src/foo';

I think it would therefore be useful if no-duplicates could be configured to have the same behaviour as before #225, i.e. to require type & normal imports to be merged.

TiddoLangerak avatar Aug 04 '17 08:08 TiddoLangerak

this should be optional

sibelius avatar Mar 14 '18 22:03 sibelius

I agree this should be controlled by an option.

ljharb avatar Mar 14 '18 23:03 ljharb

Some progress?

loyd avatar Jul 03 '18 15:07 loyd

@loyd not til somebody submits a PR ¯\_(ツ)_/¯

ljharb avatar Jul 04 '18 04:07 ljharb

Regular imports and type imports can be merged in TypeScript as well by the same logic. The difference with flow is that in TypeScript, the type imports will look like regular imports.

import {someFunction} from '../src/foo';
import type {someType} from '../src/foo';

becomes

import {someFunction, someType} from '../src/foo';

remcohaszing avatar Jun 30 '20 18:06 remcohaszing

TypeScript 4.5 also supports inline type: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#type-modifiers-on-import-names

SimenB avatar Aug 15 '22 14:08 SimenB

We'd probably have to detect TS version regardless to support that, and we may want it to be a separate option. Let's explore it in #2229.

ljharb avatar Aug 15 '22 17:08 ljharb

any progress in this?

I'd assume somebody picking up #2229 would be welcome, so I suggest starting there 🙂

SimenB avatar Jan 26 '23 14:01 SimenB