Skip to content
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

Organize Imports removes aliased imports that are in use. #22743

Closed
chriseppstein opened this issue Mar 20, 2018 · 6 comments
Closed

Organize Imports removes aliased imports that are in use. #22743

chriseppstein opened this issue Mar 20, 2018 · 6 comments
Labels
Bug A bug in TypeScript Domain: Organize Imports Issues with the organize imports feature Fixed A PR has been merged for this issue

Comments

@chriseppstein
Copy link

TypeScript Version: 2.8.0-rc, 2.8.0-insiders.20180320

VS Code Version:

Version 1.22.0-insider (1.22.0-insider)
5be9e9e7eef715539efd5341fdbc8ec5840cfc56

2018-03-20T06:06:11.908Z

Search Terms: organize import imports remove alias

Code

import { Type as TSType } from "typescript";

export function isTSType(v: any): v is TSType {
  return !!v;
}

Expected behavior:

Running "TypeScript: Organize Imports" in VS Code makes no change to the import statements.

Actual behavior:

The import statement is removed.

Work around:

Remove as <ident>from the import statement and the import statement is left untouched by the "Organize Imports" command.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 20, 2018
@ghost ghost added the Fixed A PR has been merged for this issue label Mar 22, 2018
@ghost ghost closed this as completed in #22797 Mar 22, 2018
@mjbvz
Copy link
Contributor

mjbvz commented Mar 26, 2018

@andy-ms Thank you for the quick turn around. Can we please get this in TypeScript 2.8.2 as well since the bug potentially breaks code?

@ghost
Copy link

ghost commented Mar 26, 2018

@mjbvz See #22804

@iosdev-republicofapps
Copy link

Hi, I'm seeing this issue still in VSCode 1.23.1 and I'm not using either Typescript or aliases. For example in simple code like:

// VSCode erroneously removes this import and breaks my app with "Can't find variable: reducer" errors.  Every time I add the import and save, VSCode removes the import (and it should NOT as the import is provably needed).
import reducer from "./firebaseApi";

const allReducers = combineReducers({
  // import needed
  reducer,
});

I can confirm that this has nothing to do with ESLint or Prettier and the only remedy is to set

  "editor.codeActionsOnSave": {
    "source.organizeImports": false
  },

However I want organizeImports on in general - this is the only file that it's screwing up. Any way to turn it off for just this file?

Is there an ETA on a fix?

Thanks!

@no-stack-dub-sack
Copy link

no-stack-dub-sack commented May 12, 2018

@iosdev-republicofapps I was just coming to look if this issue had already been opened, and I'm having the same problem. If you write it as:

const allReducers = combineReducers({
  reducer: reducer,
});

it will be fine. My guess is because it is not assigned to any variable, it's detecting the import as being unused. I'm wondering if, since this issue is dead, and it seems to be a little different, should this be opened as a unique issue instead? Or better yet, should this be opened in the vscode repo instead, since as you noted, it has nothing to do with TS.

@no-stack-dub-sack
Copy link

☝️ never mind, just saw your issue on that repo as well

@ghost
Copy link

ghost commented May 14, 2018

@iosdev-republicofapps That seems to work with typescript@next -- if you want this fixed right away try using a newer TypeScript version.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: Organize Imports Issues with the organize imports feature Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

6 participants