網站搜尋

如何知道在 Angular 4 專案中運行的是哪個 TypeScript 版本


所以我執行了 ng -v,它顯示了除了 TypeScript 之外的所有內容,那麼我該如何檢查我的 Angular 4 專案的 TypeScript 版本呢。

答案#1

打開 package.json 文件並檢查 devDependencies 節點。它包含專案中使用的 TypeScript 版本,如下所示。

"typescript": "^2.4.0",

你也可以像Sajeetharan在下面的回答中建議的那樣使用命令提示字元。

答案#2

如果你想要安裝作為套件依賴的確切版本,請使用 ls 指令:

npm ls typescript

或者,你可以使用 -v 標誌運行 tsc:

如果本地安裝:

node_modules\.bin\tsc -v

如果全域安裝:

tsc -v

注意:如果你打算查看 package.json 的版本號,請記住 ^2.4.0 中的尖號表示你可能會得到 2.4.x、2.5.x、2.6.x 等版本。^ 表示次要版本會在全新安裝或執行 npm update 時自動更新到最新版本。

如果版本號前面有 ~(例如 ~2.4.0),那麼在新的安裝或更新時,補丁版本號會自動更新。這意味著可以安裝以下任何版本:2.4.0、2.4.1、2.4.2 等,但不能安裝 2.5.x

答案#3

打開命令提示字元,以檢查全局安裝的版本,

類型

tsc -v

然後按下 Enter 鍵

要檢查特定專案版本,請導航到 node_modules\.bin\

./tsc -v

另一種方法是檢查專案資料夾內的 package.json

{
  "name": "angular-quickstart",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {},
  "keywords": [],
  "license": "MIT",
  "dependencies": {},
  "devDependencies": {
    "tslint": "^4.0.2",
    "typescript": "~2.1.5"
  },
  "repository": {}
}

答案#4

要知道 Typescript 的版本,使用:

ng v

這將輸出 TypeScript 版本以及其他依賴版本。我的顯示如下:

@angular-devkit/architect         0.7.1
@angular-devkit/build-angular     0.7.1
@angular-devkit/build-optimizer   0.7.1
@angular-devkit/build-webpack     0.7.1
@angular-devkit/core              0.7.1
@angular-devkit/schematics        0.7.1
@angular/cli                      6.1.1
@ngtools/webpack                  6.1.1
@schematics/angular               0.7.1
@schematics/update                0.7.1
rxjs                              6.2.2
typescript                        2.7.2
webpack                           4.9.2