简体   繁体   English

如何为 Typescript 配置 Visual Studio Code?

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

I'm writing typescript with not much experience and when I deploy my functions to the server, I get a ton of errors like "character limit for each line must be 80 characters", "blocks cannot be padded", "unexpected var, use let or const instead", indentation errors, etc. But there are so many that I feel like maybe I missed a step in configuring Visual Studio Code specifically for Typescript. For example, is there a way I can draw a vertical line in the editor to serve as a visual aid for the 80 character limit?我在写 typescript 时经验不多,当我将函数部署到服务器时,出现大量错误,例如“每行的字符数限制必须为 80 个字符”、“无法填充块”、“意外的 var,使用let or const instead”, 缩进错误等等。但有太多我觉得我可能错过了专门为 Typescript 配置 Visual Studio Code 的步骤。例如,有没有办法在编辑器中画一条垂直线作为 80 个字符限制的视觉辅助工具?

Edit: added some error examples编辑:添加了一些错误示例

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

Install the typescript compiler using the command npm install -g typescript .使用命令npm install -g typescript typescript 编译器。

For more information you can read on their official documentation https://code.visualstudio.com/docs/languages/typescript有关更多信息,您可以阅读他们的官方文档https://code.visualstudio.com/docs/languages/typescript

Try using prettier and configure vscode to format on save .尝试使用prettier并配置 vscode 以在保存时格式化 This will take care of line length and indentation errors at least.这将至少处理行长和缩进错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为 Terraform 配置 AWS MFA? - How do I configure AWS MFA for Terraform? 如何在运行测试之前自动清理 Visual Code 中的 go 缓存? - How do I automatically clean the go cache in Visual Code before running tests? 如何使用 Spring Boot 和 AWS Keyspaces 配置一致性级别? - How do I configure consistency level with Spring Boot and AWS Keyspaces? 如何为在 AWS ECS 中运行的 Docker 容器配置“ulimits”? - How do I configure "ulimits" for a Docker container running in AWS ECS? 如何配置Serverless Lambda for Graphql API with Typescript - How to configure Serverless Lambda for Graphql API with Typescript 如何配置我的 AWS Lambda 以获取输入参数 - How do I configure My AWS Lambda to take input parameters 如何使用 cloudarmor 为我的 gke ingress 配置 DDoS? - How do I configure DDoS with cloudarmor for my gke ingress? Dataproc:如何配置 Spark 驱动程序和执行程序 log4j 属性? - Dataproc: how do I configure Spark driver and executor log4j properties? 如何解决 Visual Studio 2022 中的“找不到 rc.exe”问题? " - How can I fix the issue "rc.exe not found" in Visual Studio 2022? " 如何在 Data Studio 中删除所有这些 null 值? - How do I get rid of all these null values in Data Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM