How to Check TypeScript Version?

In this tutorial, I will explain how to check the TypeScript version in various environments. While working on a project in San Francisco, I recently faced an issue where a specific TypeScript feature was not behaving as expected. After some investigation, I realized that the TypeScript version installed on my system was outdated. This tutorial will help you avoid such scenarios by ensuring you always know which TypeScript version you’re working with.

To check your TypeScript version, open your terminal and run tsc -v, which will display the currently installed version. Alternatively, you can check the package.json file under devDependencies for the TypeScript version, or use commands like npm list typescript or yarn list --pattern typescript to find the version in your project. In Visual Studio Code, open the command palette and type TypeScript: Select TypeScript Version to see and switch between installed versions.

Why Knowing Your TypeScript Version is Important

This might look silly, but you, as a TypeScript developer, should know the version of the TypeScript you are using. Here are a few important reasons:

  • Compatibility: Certain features or syntax may only be available in specific versions.
  • Debugging: Identifying version-related issues can save time during debugging.
  • Upgrading: Ensuring compatibility with other dependencies when upgrading.

Now, let me show you some methods to check the version of TypeScript.

Method 1: Check TypeScript Version via Command Line

The simplest way to check your TypeScript version is through the command line. Open your terminal or command prompt and type the following command:

tsc -v

This command will display the currently installed TypeScript version. For example:

$ tsc -v
Version 5.2.2

Here is the screenshot for your reference; I executed the above command in my local system.

check typescript version

Check out Differences Between TypeScript and JavaScript

Method 2: Check the TypeScript Version in package.json

If you’re working on a project, the TypeScript version is often specified in the package.json file. Open the package.json file and look for the devDependencies section. You should see an entry like this:

"devDependencies": {
  "typescript": "^4.5.2"
}

This indicates that the project is using TypeScript version 4.5.2.

Method 3: Using npm to Check TypeScript Version

You can also use npm to check the TypeScript version installed in your project. Run the following command in your terminal:

npm list typescript

This command will list the TypeScript version along with other dependencies. For example:

$ npm list typescript
project-name@1.0.0 /path/to/project
└── typescript@4.5.2

Check out How to Use Try Catch in TypeScript?

Method 4: Check the TypeScript Version in Visual Studio Code

If you’re using Visual Studio Code, you can easily check the TypeScript version by opening the command palette (Ctrl+Shift+P) and typing TypeScript: Select TypeScript Version. This will show the currently active TypeScript version and allow you to switch between versions if multiple are installed.

You can even see the TypeScript version in the VS code from the UI. In the right corner below, hover on TypeScript; you can see it will display the TypeScript version, as in the screenshot below.

check typescript version in vscode

Method 5: Using Yarn to Check TypeScript Version

Here is the last method to check the TypeScript version.

For those using Yarn, you can check the TypeScript version by running:

yarn list --pattern typescript

This command will list all versions of TypeScript installed in your project. For example:

$ yarn list --pattern typescript
yarn list v1.22.10
├─ typescript@4.5.2

Conclusion

It is important to know how to check your TypeScript version to maintain compatibility and ensure your development environment is up-to-date. You can check the version of TypeScript using different methods, such as the command line, package.json, npm, Visual Studio Code, or Yarn.

You may also like: