5
1

More than 3 years have passed since last update.

VSCodeでtsconfig.jsonのbaseUrlを設定しても補完が効かない場合に試すこと

Last updated at Posted at 2020-05-27

これはtsconfig.jsonに限らず、jsconfig.jsonにでも同様のことが言えると思います。

TypeScriptでコーディングをしている時、 以下のようなimport文を書いたことはないだろうか

ドット地獄.ts
import { Button } from '../../../components/atoms/Button

すなわちドット地獄である。
これを以下のようにプロジェクトのルートからimportしたい。

import { Button } from 'components/atoms/Button'

tsconfig.jsonを設定

tsconfig.jsonのcompilerOptions.baseUrlを設定すれば良い。
また、tsconfig.jsonはプロジェクトルートに配置されていること。

tsconfig.json
{
  "compilerOptions": {
    "baseUrl": "."
  }
}

設定してもVSCodeの補完が効かない場合に試すこと

  • VSCodeを再起動する

tsconfig.jsonの設定を変更したぞ、これで補完が効いて快適なコーディングができ...ない!?
設定方法を調べてみたものの、tsconfig.json設定すれば補完が効くと記載されていた。
とりあえず再起動を試したみたら補完が効くようになった。

VSCode側では、起動時にtsconfigを読み込んだパス解決設定が行われるようです。

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1