How to install Typescript and check version ?
Installing and Checking TypeScript Version
There are two common ways to install and check the version of TypeScript:
1. Globally using npm:
This is suitable if you want to use TypeScript for various projects on your system.
Installation:
Bash
npm install -g typescript
Checking Version:
Method 1:
Bash
tsc -v
This command runs the TypeScript compiler (tsc) with the -v flag to display the version.
Method 2:
Bash
npm list typescript -g
This command lists installed global packages, including TypeScript, and shows their versions.
2. Locally within a project:
This is preferred if you want to use TypeScript specifically for a particular project.
Installation:
Make sure you have Node.js and npm installed (usually included with Node.js).
Open a terminal in your project directory.
Initialize a package.json file (if not already there):
Bash
npm init -y
Install TypeScript as a development dependency:
Bash
npm install --save-dev typescript
Checking Version:
Method 1:
Bash
npx tsc -v
This uses the npm-installed TypeScript (npx) to run the compiler and display the version.
Method 2:
Bash
cat package.json | grep typescript
This searches the package.json file for the "typescript" dependency and shows its version.
Additional notes:
The latest version of TypeScript at the time of writing (February 16, 2024) is 5.3.
You can also specify a specific version during installation, e.g., npm install --save-dev typescript@4.8.4.
For more information and advanced usage, refer to the official TypeScript documentation: https://www.typescriptlang.org/
No comments:
Post a Comment
Note: only a member of this blog may post a comment.