Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dislido opened this issue Oct 30, 2023 · 2 comments
Closed

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

dislido opened this issue Oct 30, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@dislido
Copy link

dislido commented Oct 30, 2023

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.

@mjbvz mjbvz transferred this issue from microsoft/vscode Oct 30, 2023
@mjbvz mjbvz removed their assignment Oct 30, 2023
@RyanCavanaugh
Copy link
Member

This is addressed by #56090

TypeScript doesn't know anything about external lint programs and can't adjust its behavior accordingly, so the contents of your .eslintrc.js aren't relevant in this situation.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 30, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants