Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 894
Leo Jiang Avatar asked Oct 07 '21 11:10

Leo Jiang


People also ask

Why is IntelliSense not working in VS Code?

Troubleshooting# If you find IntelliSense has stopped working, the language service may not be running. Try restarting VS Code and this should solve the issue. If you are still missing IntelliSense features after installing a language extension, open an issue in the repository of the language extension.

What is TypeScript IntelliSense?

IntelliSense. IntelliSense shows you intelligent code completion, hover information, and signature help so that you can write code more quickly and correctly. VS Code provides IntelliSense for individual TypeScript files as well as TypeScript tsconfig. json projects.


Video Answer


1 Answers

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.

like image 66
Leo Jiang Avatar answered Oct 09 '22 00:10

Leo Jiang