簡體   English   中英

如何為 Typescript 配置 Visual Studio Code?

[英]How do I configure Visual Studio Code for Typescript?

我在寫 typescript 時經驗不多,當我將函數部署到服務器時,出現大量錯誤,例如“每行的字符數限制必須為 80 個字符”、“無法填充塊”、“意外的 var,使用let or const instead”, 縮進錯誤等等。但有太多我覺得我可能錯過了專門為 Typescript 配置 Visual Studio Code 的步驟。例如,有沒有辦法在編輯器中畫一條垂直線作為 80 個字符限制的視覺輔助工具?

編輯:添加了一些錯誤示例

26:32   warning  'context' is defined but never used                                           @typescript-eslint/no-unused-vars
   45:1    error    Missing JSDoc comment                                                         require-jsdoc
   46:1    error    Expected indentation of 4 spaces but found 2                                  indent
   47:1    error    Expected indentation of 4 spaces but found 2                                  indent
   48:1    error    Expected indentation of 4 spaces but found 2                                  indent
   49:1    error    Expected indentation of 0 spaces but found 2                                  indent
   55:3    error    Unexpected var, use let or const instead                                      no-var
   55:7    error    Type number trivially inferred from a number literal, remove type annotation  @typescript-eslint/no-inferrable-types
   55:28   error    Missing semicolon                                                             semi
   56:3    error    Unexpected var, use let or const instead                                      no-var
   56:7    error    Type string trivially inferred from a string literal, remove type annotation  @typescript-eslint/no-inferrable-types
   56:34   error    Missing semicolon                                                             semi
   57:3    error    Unexpected var, use let or const instead                                      no-var
   57:7    error    Type string trivially inferred from a string literal, remove type annotation  @typescript-eslint/no-inferrable-types
   57:29   error    Missing semicolon                                                             semi
   64:1    error    This line has a length of 83. Maximum allowed is 80                           max-len
   64:84   error    Missing semicolon                                                             semi
   66:20   error    Missing semicolon                                                             semi
   67:50   error    Missing semicolon                                                             semi
   68:21   error    Missing semicolon                                                             semi
   70:20   error    Missing semicolon                                                             semi
   71:26   error    Missing semicolon                                                             semi
   72:47   error    Missing semicolon                                                             semi
   73:6    error    Trailing spaces not allowed                                                   no-trailing-spaces
   78:1    error    This line has a length of 112. Maximum allowed is 80                          max-len
   78:113  error    Missing semicolon                                                             semi
   81:24   error    Expected parentheses around arrow function argument                           arrow-parens
   82:47   error    Missing semicolon                                                             semi
   85:20   error    Missing semicolon                                                             semi
   86:21   error    Missing semicolon                                                             semi
   88:20   error    Missing semicolon                                                             semi
   89:26   error    Missing semicolon                                                             semi
   90:47   error    Missing semicolon                                                             semi
   91:6    error    Trailing spaces not allowed                                                   no-trailing-spaces
   93:1    error    Trailing spaces not allowed                                                   no-trailing-spaces
   94:48   error    Missing semicolon                                                             semi
   99:32   warning  'context' is defined but never used                                           @typescript-eslint/no-unused-vars
  130:18   warning  'response' is defined but never used                                          @typescript-eslint/no-unused-vars

使用命令npm install -g typescript typescript 編譯器。

有關更多信息,您可以閱讀他們的官方文檔https://code.visualstudio.com/docs/languages/typescript

嘗試使用prettier並配置 vscode 以在保存時格式化 這將至少處理行長和縮進錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM