We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

TypeScript Language Server

We've used tsc from the command line to compile our TypeScript code, but that's often not how it's used in practice... at least not directly. In many projects, TypeScript is primarily used as a language server to provide type checking and other features in your IDE. It powers stuff like:

  • Auto-completion
  • Type checking (showing and underlining errors in your editor)
  • Jumping to definitions

That's why we sometimes joke about TypeScript being a "glorified linter". There are a few reasons I point out this distinction, but the first is to understand that your editor tooling and your build tooling are separate. If your editor is using TypeScript 4 and one tsconfig.json file, but your build tooling is using TypeScript 5 and another tsconfig.json file, you can run into scenarios where your editor and what's being compiled in production are out of sync.

All this to say... keep them in sync! Most editors are smart at this and do it automatically, but it's worth knowing how to check what your editor is using under the hood.

  1. Most editors will default to using the version of TypeScript installed in your project. If you have a node_modules folder, it will use that version.
  2. If you don't, or you don't have your editor opened to the right project directory, it will likely use:
    • The version of TypeScript installed globally on your machine
    • The version of TypeScript bundled in the editor itself
    • The version of TypeScript specified in your editor settings (e.g. .vscode/settings.json, .zed/settings.json, etc.)

Pin the version of TypeScript in your project to avoid this confusion, and make sure your editor is using that version.

Restarting the TS Server

Language servers are notorious for kinda just... getting stuck. If you notice that your editor is not picking up on type errors, or is not providing auto-completion, step #1 should probably be to restart the TypeScript language server.

  • In VS Code: Cmd/Ctrl+Shift+P > TypeScript: Restart TS Server
  • In Zed: Cmd/Ctrl+Shift+P > Restart Language Server
  • In Neovim: :lsp restart (or :LspRestart)

Assignment

Let's pin the version of TypeScript used in our moonshot proof of concept AI Support site.

npm i -D typescript

Notice that this adds the TypeScript version to your package.json file.

Run and submit the CLI tests.