Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yarn workspaces in Visual Code for Tyescript

I have a Lerna/Yarn workspaces monorepo with many packages that use TypeScript. Each package.json contains a tsconfig.json and a script “build:compile” that calls tsc to compile the source code.

I have two problems with Visual Code:

  1. There is no way to watch-compile all packages with one command. I can only run tsc watch for each package individually, which is quite cumbersome.

  2. Go to declaration into another package always jumps to the compiled d.ts file, but not to the source code.

like image 673
user3612643 Avatar asked Oct 19 '25 18:10

user3612643


1 Answers

For #1, consider using project references to define a master project that references all the packages and then run tsc -b -w on the master project. (There are also lerna run and yarn workspaces run, but perhaps they don't work if you need to watch-compile all packages concurrently?)

For #2, enable the declarationMap compiler option in tsconfig.json and rebuild all packages, and then "Go to Definition" should go to the source code.

like image 135
Matt McCutchen Avatar answered Oct 22 '25 07:10

Matt McCutchen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!