Skip to content

Add path alias to the auto import suggestions  #39459

Closed

Description

@Maus3rVonDutch

Right now the auto import feature provides the file location of any symbol, which is great but could be improved upon. In the ts compiler options you have the option to provide path aliases, so you can combine multiple symbols in one import declaration:

tsconfig.json

{
    "compilerOptions": {
        ...
        "paths": {
            "@my-application/common": [
                "./src/app/common/index"
            ],
            "@my-application/module1": [
                "./src/app/module1/index"
            ],
            "@my-application/module2": [
                "./src/app/module2/index"
            ]          
        }
}

With this configuration you can import multiple classes in one declaration:

import { CommonA, CommonB } from '@my-application/common';
import { ClassA, ClassB, ClassC } from '@my-application/module1';
import { ClassD, ClassE } from '@my-application/module2';

It would be a great feature if the import suggestion provider would be able to pick up those paths from the tsconfig.json file and provide those aliases as well. Maybe the provider could have a configuration that allows you to include both options (the local file path and the alias) or just one or the other. As a note, when choosing the alias, the import feature would have to add the symbol to any existing declaration (and not just always add the alias as a new import line)

Activity

  1. added
    typescript
    on Dec 2, 2017
  2. mjbvz commented on Dec 7, 2017

    @mjbvz
    Contributor

    This issue was moved to microsoft/TypeScript#20525

  3. locked and limited conversation to collaborators on Jan 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

typescript

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions