Home > database >  Typescript update
Typescript update

Time:04-30

I want to make sure I have updated my project to the latest version of Typescript. The command I have ran was this npm install -g typescript@latest. Also when I run tsc -v that will return Version 4.6.4. I there anything more I need to do in the tsconfig.json or the gulpfile.js to be sure this is getting compile with the latest version? Or anything in Visual Studio I need to install?

When I run ng version I see 1.8.10

Angular CLI: 6.2.1
Node: 16.15.0
OS: win32 x64
Angular: 2.2.4
... common, compiler, core, forms, http, platform-browser
... platform-browser-dynamic, upgrade

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.8.1
@angular-devkit/core         0.8.1
@angular-devkit/schematics   0.8.1
@angular/cli                 6.2.1
@angular/router              3.2.4
@schematics/angular          0.8.1
@schematics/update           0.8.1
rxjs                         5.0.0-beta.12
typescript                   1.8.10

But when I run tsc -v I see 4.6.4

Version 4.6.4

CodePudding user response:

npm install -g typescript@latest means you install the package globally in Node.js folder (not in your project folder)

As the document

global packages are all put in a single place in your system (exactly where depends on your setup), regardless of where you run npm install -g

For adding that package to your project as a dependency, we have 2 approaches

The first approach

Modifying the expected package version specifically in package.json. In your case, it would be "typescript": "^4.6.4" (it will be compatible from version 4.6.4 to 5.0.0)

"dependencies": {
   "typescript": "^4.6.4"
},

And then running

npm install

Or

yarn install

(these commands to help you update local packages in your project)

This approach is preferable because of package stabilization. If you always try to install the latest package without proper testing for compatibility, your current application may be crashed

The second approach

You need to go to your project folder in your terminal by commands (like cd)

Note that you need to be at the root level of your project folder which has package.json

And then you can use this

npm install --save-exact typescript@latest

If you consider using yarn, you can follow this command

yarn add typescript@latest --exact

You check this link to understand more about other npm install commands with options

  • Related