Skip to content

Extract to function can use inline imports  #38177

@mjbvz

Description

@mjbvz

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbolFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions