Skip to content

Extract to function can use inline imports #38177

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
mjbvz opened this issue Apr 25, 2020 · 1 comment · Fixed by #38213
Closed

Extract to function can use inline imports #38177

mjbvz opened this issue Apr 25, 2020 · 1 comment · Fixed by #38213
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Fixed A PR has been merged for this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Apr 25, 2020

TypeScript Version: 3.9.0-dev.20200423

Search Terms:

  • refactor / refactoring
  • extract to function / method

Code
For the TypeScript code:

foo.ts

export class Foo { }
export const foo = new Foo();

index.ts

import { foo } from './foo';

{
    const x = foo;
    console.log(x);
}
  1. Select console.log(x); and run the extract to function refactoring

Bug:
This adds an inline import type for Foo:

import { foo } from './foo';

{
    const x = foo;
    newFunction(x);
}

function newFunction(x: import("/Users/matb/projects/san/foo").Foo) {
    console.log(x);
}

Instead, it should add the import of Foo to the existing import at the top of the file

Related Issues:

@jessetrinity jessetrinity added Fix Available A PR has been opened for this issue Domain: Refactorings e.g. extract to constant or function, rename symbol labels Apr 29, 2020
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.9.3 milestone Apr 30, 2020
@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Apr 30, 2020
@DanielRosenwasser DanielRosenwasser added Fixed A PR has been merged for this issue and removed Fix Available A PR has been opened for this issue labels May 4, 2020
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented May 4, 2020

Thanks @a-tarasyuk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants