Search code examples
typescriptvisual-studio-codemonorepo

How to refresh monorepo TypeScript types in VS Code without reloading the window


I have an open source project called react-querybuilder that is maintained as a monorepo. Most of the TypeScript type definitions live in the ts package.

When I have a file open in VS Code for one of the other packages that imports a type from @react-querybuilder/ts, the types seemed to be cached based on the packages/ts/dist folder at the time VS Code launches.

When I make an update to a type in the ts folder and rebuild the @react-querybuilder/ts package, the change is not automatically applied to the other projects, even if I close and reopen all the files.

The only way I have found to update the types cache is to reload the VS Code window. Unfortunately my work computer is old and not built as a great developer machine, so this can take some time. Is there a way to refresh the types without completely reloading the window?


Solution

  • There might be some optimization to your codebase that prevents this problem from occurring, but in the mean time, there's a "TypeScript: Restart TS Server" command that refreshes the types and is a bit faster than reloading the entire window. You can also use it to update the types after installing new npm packages.

    I personally find these two keyboard shortcuts useful: alt+r restarts TypeScript, whereas alt+command+r reloads the window.

      {
        "key": "alt+r",
        "command": "typescript.restartTsServer"
      },
      {
        "key": "alt+cmd+r",
        "command": "workbench.action.reloadWindow"
      },