11

I use VSCode (1.17.2 at time of writing) with TypeScript (2.5.2). When I start to use a class in .ts file that is not yet imported, there is error and the class name i underlined with possibility to use Quick Fix bulp to import it. But it uses absolute path (actually relative to project root) to the file, e.g.

import { FormattedValue } from 'src/app/entities/formattedValue'; 

It works but when I create modules that can be just copied to different projects (having different project's folder structure) I need the paths to be relative. So when I start using e.g. FormattedValue in file src/app/entities/xy.ts, the generated import should look like

import { IFormattedValue } from './formattedValue'; 

Is there a way how to setup VSCode to use relative paths in quick fix generted imports?

1
  • 2
    See if this answers your question: stackoverflow.com/q/47330773/1028230 Looks like at 2.5.2 maybe not, but at 2.9+, you can with the typescript.preferences.importModuleSpecifier setting. Commented Nov 16, 2018 at 3:15

1 Answer 1

13

In your vscode settings, add the following setting:

"typescript.preferences.importModuleSpecifier": "relative" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.