Typescript: Import path quick suggestions - jsconfig aliases not recognised

Created on 11 Oct 2017  路  7Comments  路  Source: microsoft/TypeScript

_From @mudrz on October 10, 2017 7:58_

  • VSCode Version: 1.17.0
  • OS Version: macOS High Sierra 10.13


Reproduces without extensions: Yes

Doesn't work properly with aliases added in jsconfig.json https://code.visualstudio.com/docs/languages/jsconfig

Sample jsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "ClientApp/*": ["./ClientApp/*"]
    }
  }
}

Expected behaviour

import Something from 'ClientApp/...'

will pull path intellisense for folder ClientApp

Existing extension path-intellisense for example can also be configured with aliases in settings.json

"path-intellisense.mappings": {
    "ClientApp": "${workspaceRoot}/MvcProject/ClientApp",
  }

_Copied from original issue: Microsoft/vscode#35970_

Quick Fixes Fixed Suggestion

Most helpful comment

Same issue. In my case, TypeScript correctly understands the alias once the full path is set out and is able to pull exports from the file. But autocompletion on the file name returns the name of the alias itself -- e.g. if I have a path for @alias/to/file, typing @alias/ presents @alias/* (note the duplication) as an autocomplete option rathe than to/file.

All 7 comments

Tested on TS 2.5.3 and latest TS 2.6.0 dev

I see ClientApp/* as a suggestion in this case:

Trace  - 2:35:20 PM] Response received: completions (15). Request took 4 ms. Success: true 
Result: [
    {
        "name": "ClientApp/*",
        "kind": "external module name",
        "kindModifiers": "",
        "sortText": "ClientApp/*",
        "replacementSpan": {
            "start": {
                "line": 1,
                "offset": 34
            },
            "end": {
                "line": 1,
                "offset": 34
            }
        }
    },
    {
        "name": "node",
        "kind": "external module name",
        "kindModifiers": "",
        "sortText": "node",
        "replacementSpan": {
            "start": {
                "line": 1,
                "offset": 34
            },
            "end": {
                "line": 1,
                "offset": 34
            }
        }
    },
    {
        "name": "node",
        "kind": "external module name",
        "kindModifiers": "",
        "sortText": "node",
        "replacementSpan": {
            "start": {
                "line": 1,
                "offset": 34
            },
            "end": {
                "line": 1,
                "offset": 34
            }
        }
    },
    {
        "name": "react",
        "kind": "external module name",
        "kindModifiers": "",
        "sortText": "react",
        "replacementSpan": {
            "start": {
                "line": 1,
                "offset": 34
            },
            "end": {
                "line": 1,
                "offset": 34
            }
        }
    },
    {
        "name": "react",
        "kind": "external module name",
        "kindModifiers": "",
        "sortText": "react",
        "replacementSpan": {
            "start": {
                "line": 1,
                "offset": 34
            },
            "end": {
                "line": 1,
                "offset": 34
            }
        }
    }
]

I just checked, and this is what I get
screen shot 2017-10-12 at 18 58 46

I also noticed that object props Intellisense also doesn't work

Recreated the same project config here https://github.com/mudrz/jsconfig-tests

(This is TS 2.5.3, I haven't updated to TS 2.6 yet, I'll have some more time to test that in the following days)

_Edit:
Intellisense works, it was a typo, but aliases don't_

jsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "App/*": ["./ClientApp/*"]
    }
  },
  "include": ["**/*.js"]
}

I just installed TS 2.6 and it fixes the performance issues I've had, but not the aliases resolution

Updated the test project also with 2.6

How do you get this response, can you share what compilerOptions are you using

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "App/*": ["./ClientApp/*"]
    }
  },
  "include": ["**/*.js"]
}

screen shot 2017-10-18 at 10 35 39

_edit:
fyi with VS Code 1.18 the alias resolution still doesn't work correctly_

Not sure if anything is happening here, but this is still a big issue with latest VSCode Insiders (1.19-insiders), and Typescript@next:

ts270dev

Even trying to not use the alias results in the same bad input (ie. trying to import from 'GLOBAL/..' gives the same incorrect list of suggestions)

in tsconig.json:

    "paths": {
      "@admin/*": [ "app/admin/*" ],
      "@app/*": [ "app/*" ],
      "@coaching/*": [ "app/coaching-shared/*" ],
      "@env/*": [ "environments/*" ],
      "@wltGlobal/*": [ "GLOBAL/*" ]
    },

Hey, I provided a minimal reproduction repo on this (duplicate) issue: https://github.com/Microsoft/vscode/issues/39983

Edit: saving you a click: https://github.com/Zephir77167/vscode-intellisense-bug

The bigger issue is that even without using the path alias', VC Code has a problem if you try to do an import on an absolute path. Just try importing from 'app/ ..' and it'll show all sorts of incorrect things.

Same issue. In my case, TypeScript correctly understands the alias once the full path is set out and is able to pull exports from the file. But autocompletion on the file name returns the name of the alias itself -- e.g. if I have a path for @alias/to/file, typing @alias/ presents @alias/* (note the duplication) as an autocomplete option rathe than to/file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanielRosenwasser picture DanielRosenwasser  路  3Comments

remojansen picture remojansen  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

wmaurer picture wmaurer  路  3Comments

siddjain picture siddjain  路  3Comments