9

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?

4
  • 2
    Could you possibly share the output of the "bunch of Typescript errors"? Commented Oct 17, 2021 at 19:28
  • It's a lot of file not found, no implicit any, etc because it's not using the right config Commented Oct 19, 2021 at 14:58
  • Can you edit your question to show a fragment of the errors? Maybe that can give us a hint into the right direction. Commented Oct 19, 2021 at 15:40
  • You can enable TS server logs through the Command Palette. That may help give you an idea of which config file VSC is loading after your lint runs. Without more details of your error messages it's challenging to pinpoint a cause here. Output of your logs/messages would certainly help. Commented Oct 19, 2021 at 17:01

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.