Skip to content

"Organize imports" removes imports necessary for declaration file #22974

Closed
@dsherret

Description

@dsherret

TypeScript Version: typescript@2.9.0-dev.20180328

Search Terms: organize imports declaration

Code

Take this file:

import {NoteStore} from "./NoteStore";
import {Note} from "./Note";

export class SomeClass {
    constructor(private readonly noteStore: NoteStore) {
    }

    getNotes() {
        // implicit return type: Note[]
        return this.noteStore.getValues();
    }
}

With compiler option declaration: true

Expected behavior:

import {Note} from "./Note";
import {NoteStore} from "./NoteStore";

// ...class declaration omitted...

Actual behavior:

import {NoteStore} from "./NoteStore";

// ...class declaration omitted...

And causes this compile error: Return type of public method from exported class has or is using name 'Note' from external module "fileNameGoesHere.ts" but cannot be named.

Playground Link: N/A

By the way, I ran "organize imports" on about 800 files. Works really well other than this problem and it puts imports that were previously on multiple lines onto one... so that will break my linting rule for "max-line-length". Luckily it's easy to write a script to investigate and break them back onto multiple lines 😄

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