ggascoigne / prettier-plugin-import-sort

Prettier plugin to pass javascript and typescript through import-sort
MIT License
110 stars 11 forks source link

Type imports are broken #29

Open SebTVisage opened 5 months ago

SebTVisage commented 5 months ago

Hi.

Problem: If I run prettier with the plugin on the file containing this import:

import {
  type DELAYED_TASK_NAME, // This is badly interpreted by the plugin
  DelayedTasksService,
  PendingTask,
} from '../domain/delayed-tasks-service.interface';

It gets transformed into:

import {
  DELAYED_TASK_NAME,
  DelayedTasksService,
  PendingTask,
  type, // keyword `type` is handled like an imported member
} from '../domain/delayed-tasks-service.interface';

Which is breaking TS.

Context: I'm using this plugin v0.0.7 with import-sort-style-module v6.0.0. Here's my config file

{
  ".js, .jsx, .es6, .es, .mjs, .ts, .tsx": {
    "parser": "typescript",
    "style": "module"
  }
}

Workaround I can fix it by manually changing the code above to:

import {
  DelayedTasksService,
  PendingTask,
} from '../domain/delayed-tasks-service.interface';
import type { DELAYED_TASK_NAME } from '../domain/delayed-tasks-service.interface';

But that's annoying. And using the original syntax can create errors if we do not notice prettier's changes

SebTVisage commented 5 months ago

This may be an issue with the upstream sort-import. It seems completely dead though, compared to issues being replied to in this repository. Is the project unmaintained?

HaveSpacesuit commented 2 months ago

I don't know if this project is maintained anymore; I found a workaround to the issue by disabling TypeScript > Preferences: Prefer Type Only Auto Imports in VS Code settings; it won't add type for auto-imports, but when Prettier formats the imports, it does add a type-only import on its own line.