Leo Jiang
Leo Jiang

Reputation: 26145

VS Code's Typescript IntelliSense breaks every time I `git commit`

I have a project with several tsconfig.json files in different directories. Usually, VS Code uses each tsconfig.json only for the directory it's in.

When I git commit, I use Husky to run Eslint on the changed files. Eslint uses @typescript-eslint/parser. After the code commits, I get a ton of Typescript errors in VS Code. Restarting the TS server fixes it, but it's slow for a few minutes (I think it's rebuilding the TS cache?).

I think what's happening is when Eslint runs, it uses one (or more) of the tsconfig.json files, depending on the changed files' location. Then, VS Code somehow detects that a specific tsconfig.json was used, then it uses it for my whole project. I want VS Code to continue using the tsconfig.json files it detected, rather than picking up the tsconfig.json used by Eslint.

What are some things I can try to prevent this? Is there a way to temporarily disable VS Code's TS server while I'm committing code? Or is there a proper way to prevent VS Code from using a tsconfig.json file incorrectly?

Upvotes: 9

Views: 493

Answers (1)

Leo Jiang
Leo Jiang

Reputation: 26145

I found the issue:

There are .d.ts files that are included in multiple tsconfig.jsons. There are some type definitions in different .d.ts files that override each other, so import order matters. For unknown reasons, after I git commit, VS Code imports them in a different order.

I fixed it by no longer overriding definitions.

Upvotes: 1

Related Questions