Skip to content

Intellisense & Quick fix: Add import type from 'xxx.ts' #56259

Closed as not planned
@dislido

Description

@dislido

I have a typescript project that includes the following configurations:
.vscode/settings.json

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.fixAll": true
  }
}

.eslintrc.js

module.exports = {
  rules: {
    '@typescript-eslint/consistent-type-imports': 'error',
    'import/no-duplicates': 'error',
  },
}

Now I have a file that defines a customElement my-element.ts;

export class MyElement extends HTMLElement {}

customElements.define('my-element', MyElement);

Usually, I directly import it as side effect;

import './my-element';

const el = document.createElement('my-element');

Sometimes I need to use its type, when I input MyElement, Intellisense or Quick fix will add a named import, which violated the eslint rules.

import './my-element';

import { MyElement } from './my-element';

const el = document.createElement('my-element') as MyElement;

When I save this file, it will be auto fixed: the side effect import disappears, and the named import becomes a type import, Then I lost the ./my-element import;

import type { MyElement } from './my-element';

const el = document.createElement('my-element') as MyElement;

If we have an "Add import type from './my-element.ts'" option in Intellisense & Quick fix, we can solve this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions