了解如何在本機安裝 TypeScript,以便在自己的電腦上解 Exercism 的練習
你需要 NodeJS LTS。
💡 這個軌道可能也能搭配較舊的穩定版本,以及「current」版本運作。 不過,按照設計,奇數版本永遠不穩定。 請務必安裝偶數版本的 NodeJS。
請使用 Node.JScorepack來安裝 Yarn 4+:
corepack enable yarn
一般來說,你需要開啟一個新的終端機,才能使用剛安裝好的執行檔。
$ node -v
v20.15.0
$ corepack -v
0.28.1
$ corepack yarn -v
v4.3.1
注意:你的版本可能會與這裡不同。
每個練習都需要一些工具才能執行測試:
你可以在每個練習目錄中執行以下指令來安裝這些工具:
$ corepack yarn install
視你使用的編輯器而定,為了搭配 Plug'n'Play 安裝方式運作,你需要在每個練習中安裝 Editor SDK。 在撰寫本文時,支援以下編輯器:
舉例來說,如果你使用 VSCode,要執行的指令如下:
$ corepack yarn install
➤ YN0000: · Yarn 4.3.1
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Post-resolution validation
➤ YN0060: │ # [...]
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 0s 566ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 0s 768ms
$ corepack yarn dlx @yarnpkg/sdks vscode
➤ YN0000: · Yarn 4.3.1
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + @yarnpkg/sdks@npm:3.1.3, and 103 more.
➤ YN0000: └ Completed in 0s 509ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 104 packages were added to the project (+ 2.87 MiB).
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed in 0s 270ms
➤ YN0000: · Done in 0s 881ms
➤ YN0000: Cleaning up the existing SDK files...
➤ YN0000: ┌ Generating SDKs inside .yarn/sdks
➤ YN0000: │ ✓ Eslint
➤ YN0000: │ ✓ Prettier
➤ YN0000: │ ✓ Typescript
➤ YN0000: │ • 5 SDKs were skipped based on your root dependencies
➤ YN0000: └ Completed
➤ YN0000: ┌ Generating settings
➤ YN0000: │ ✓ Vscode (updated 🔼)
➤ YN0000: └ Completed
你必須在_練習目錄內_執行安裝,才能執行測試。 由於已啟用 Yarn 4 PnP,在每個練習目錄中安裝相依套件並不會安裝所有相依套件的完整副本。
如果之後你的編輯器對eslint、prettier或typescript顯示錯誤,請重新載入視窗或重新開啟編輯器。